I am using NPlot charting library to draw several plots illustrating signal fluctuations. The plots are inserted one beneath the other in a flowlayoutpanel1.
The x axis is the time. The y is the value of the signal.
I've added a trackbar at the bottom, along the x axis. When the user moves the trackbar, the value of each signal is displayed somewhere (in relation to the trackbar's position).
All of this is already functional.
I've been asked to add some visual way to illustrate the precise time where the trackbar is. They want some sort of vertical line that would move with the trackbar, over all the Nplots. However they are open to alternatives.
I have tried drawing the line but it's difficult to draw in relation to the trackbar's position. Also it ends up being drawn BEHIND the Nplots.
I've also tried drawing a static grid on the flowpanel but the Nplots are not transparent, and my boss doesn't like each plot having a individual grid for aesthetic purposes.
At this point i'm open to any "out-of-the-box" suggestions, or corrections on my implementation. I'm self taught in C# so i haven't done anything like this before.
Please help!
EDIT: I have gotten something slightly better by using a label with a border, stretching it to be tall and having width of 1. This creates a Line that goes over all other control. Now my biggest challenge is calculating the position of the trackbar pointer to make the line match it...
After a lot of fiddling, i found that the only way to have a line drawn over all other controls was NOT to use the Graphics drawline, as the controls placed on top were not transparent and i could not access their graphics component (was a imported control not a .NET class).
I ended up going with the EDIT solution, took a label with a border and put the width to 1, creating a simple line instead of a box.
The position formula took a lot of fine tuning, the way to go was to calculate (estimate) the width between two trackbar ticks an add a tiny offset for the control itself. Using the traback's pointer Value property, i could calculate the position of the label/line so that it would follow the trackbar pointer. There is a minuscule offset sometimes formed but not well seen to the naked eye.
Related
I have different XAML Line Controls defined inside a MapControl. They change the rotation, color, ... so I thought it was better to do with lines that with MapPolyline which are supposed to stay static.
When panning around the map I found that when the origin of the lines are out of the MapControl, sometimes the lines dissappear, sometimes not. They dissappear only when outside the MapControl BUT on the right side or the lower side. THat doesn't happen when they pan out left side or upper side.
Obviously, I want them in the screen everytime, I don't want to dissappear them.
Any idea why it happens? And how can I get them visible all the time?
Lines visible when origin (orange point) inside the MapControl
Lines hidden when Lines origin outside right side. Orange point is partially visible.
Lines visible when origin outside left side. Even the orange point is outside the control, but lines are still visible.
It appears there is some code that toggles the visibility of attached XAML items based on whether the attached points are in the viewport. You could work around this by introducing additional points along the line.
In general, It's recommended to use MapElements rather than attached XAML for most scenarios. XAML should really only be used for things like dialogs with rich UI where you have relatively few such objects attached to the map. MapPolyline will perform better even for scenarios where you want to update the properties and position and will stay in sync with map motion much better than XAML.
I have found a solution for the dissapearing lines problem.
All the lines and XAML shapes that were just on the MapControl should be grouped inside a canvas, width the correct width and height (in my case the max length of the lines in both dimensions and also negative and positive directions, center/anchor the canvas in the MapControl.Center and play with margins tofit all the controls correctly).
For all the tests I have done, lines stays in th screen even both starting point and the ending point are not in the screen.
I have a WPF application where I used DevExpress charts to display some data. I want to get rid of them and use LiveCharts, but I want to display a circle in the chart point closest to the mouse cursor when it is inside the chart. I have tried sections and I can show lines that cross in the point, but I can't mark that point as it automatically does when you hover over it. Is there a way to do this without changing the source code?
I think you can get your answer from this example.
By calculating the closest point to your mouse (like in the example, you can then change the style of your chart point. In the example, the x-axis lable at the specific point gets highlighted.
I'm making a little chess game in wpf, and I'm having trouble to find the right way I should move and display pieces on the chessboard...
To draw the chessboard I use a UniformGrid (8 * 8) which I fill on init in "code behind" with Rectangle shapes.
Then I want to add my pieces on this grid, which are png images in a Image control I also create in "code behind".
I thought about putting these images in the same cell of the grid as my Rectangle controls, but I see the issue that I wouldn't be able to animate the move of a piece that way, since it will go from one location to another directly.
So I thought about adding the pieces to the parent control, and then use the RenderTransform property to set their positions.
The thing is, I can't figure out what I have to do so that if the parent control is resized the pieces stay at the right position.
Is there a way to set the translation once and for all without having to redefine it at resize? I thought about assigning the position and size of the Rectangle elements on the pieces control, but this doesn't seem to be doable in wpf...
Am I just doing it all the wrong way and there is a better option to do this?
Thanks for your help, any suggestions are welcome.
I want to write a GUI editor in C# for AutoIt, but I am not good enough with C#. I want to draw a square (focused) around an object when any object in the GUI is pressed. Like this:
Is there any library to make easier to write this kind of thing?
Square is drawn with one of DrawRectangle functions. Each of them requires a pen. Usually we use ordinary solid pen, but you need a pen with changed DashStyle property. For dotted lines change this property to DashStyle.Dot. You can also experiment with DashPattern property.
To draw little squares around the big square you need one of FillRectangle functions. Each of them requires a brush. You need a white brush, which is conveniently predefined for you to use. After filling a rectangle, you have to draw a rectangle over it with the same dimensions. These two functions together give an impression of empty and lined rectangle.
To make little squares a little rounded, like they are in the image, you have to change a pen parameter used when calling DrawRectangle. Experiment with LineJoin, and other properties of the Pen class.
This is very hard for a simple question that you posted. There are a lot of things that you need to take care of.
First I would suggest to make a class that will have a Rectangle property since you can't subclass Rectangle because it is a structure.
You will need to handle the drawing, that is the simplest task as mentioned in the other answers so I'm not going to be specific about that.
Since you have small squares that indicate that the rectangle can be resized, you will have to implement method that checks whether the mouse point is within the big rectangle or some of the small suqares. In this case you should change your cursor to indicate the possibility of resizing.
To handle moving (but not resizing) of the rectangle you will have either to make a new small square with the sign for moving in all directions or you will handle that using cursor when the mouse position is within the Big Rectangle.
The main problem is identifying what to change when resizing, you have two options:(1) to change Location and Size properties or to change X, Y, Width and (2)Height properties of the rectangle. For instance, when you are moving top-right corner you should change both Location and Size in first case or Y and Width is you are using second option.
When you move the mouse while it is clicked, you should watch out in which direction mouse moves. If you split the viewport in quadrants where the center of your rectangle is the center of the Decartes coordinate system, by identifying in which quadrant is the mouse you will know which corner (or edge) of the quadrant you need to move.
Each mouse move will have to call Invalidate() because you can't use Xor like in C++. Therefore, when your Rectangle is displayed, you should be in a special mode where everything that not moves (not changes, everything except Rectangle and selected control) should be drawn to the Bitmap that is used between two redraws and you should only draw what is moving.
As you can see, there is a lot of things that should be taken care of. You should start with this only after you are sure that you have already implemented other parts of your program.
I am a not very good at C# yet so bear with me,
I am trying to create a program that can edit pictures of small sizes (16x16, 32x32, etc...), specifically Minecraft texture files. I need to create a drawing surface where I can display rectangles on. I want to use WPF rectangles because they are working for me so far. I tried putting them on a WPF Grid panel but creating a good size grid panel with 1 pixel wide rows and columns takes about thirty seconds and that's quite a lot of time. Any ideas are helpful.
I'm getting the feel that your direction might not be the most efficient.
Of course, it's quite possible to convert an image into a lot of rectangles, but it's really not efficient once you have a lot of pixels. (32x32 = 1024 rectangles.)
So, instead of going along with WPF rectangles, like you want to, I would urge you to reconsider. Instead, try to work with WriteableBitmap.
From your vague description, I assume you are writing a paint like program, where the user can select a color and draw with the mouse on the texture with that color. By binding the WriteableBitmap up to an Image tag, and adding an event listener to the MouseMove event, you can get the mouse position, and whether the left/right mouse button is pressed or not. Combine that with some math involving the x position and the ActualWidth, and the y position and ActualHeight, of the Image, you can find the pixel the mouse is over, and set the color of that pixel.
So basically, Rectangles are not your best bet. Especially if you try to make a 32x32 grid to contain them. Use WriteableBitmap.
I would suggest using something more lightweight like DrawingVisuals. Alternatively if you really just want to display the textures you can preprocess them and display the result as a normal Image.