In Winform, i have a ComboBox at the bottom of the form.
when i run the application, ComboBox draws dropdown list in downward direction which goes out of the form borders.
how can i make ComboBox Dropdown list to draw in Upward direction ?
Thanks in advance.
It's not immediate but you can do it, I'll just outline the steps you need:
Attach an event handler to ComboBox.DropDown.
Convert the Left/Bottom location of the ComboBox to screen cordinates and add them an offset (+1 for example to both values).
Use use WindowFromPoint() to get the handle of the dropped down window (it's below the control, that's why +1).
Get the bounds of the dropped window (you can use CB_GETDROPPEDCONTROLRECT or GetWindowRect(), as you prefer).
Move the window to the new location (ComboBox top - dropped down window height) using MoveWindow().
That's all
EDIT
Note that you may merge point 2 and 4, with a single SendMessage with CB_GETDROPPEDCONTROLRECT you can get the bounds of that window and the location to use as parameter for WindowFromPoint(). In this way you do not assert that the dropped down window is always downward (it's not sure when the window touches the screen bounds and it may even change in future versions).
Related
So I tried building my game, but I saw that the objects that were set on a panel didnt keep their position. If I click on max window size then the objects move away from their original position. How can I solve this? (see images for extra info)
You should set ui elements' anchor position
For example my Restart button is in top-left place. When screen size change, it doesn't change position. To do this, click your ui object, click anhcor-presets section, press alt key and select a position which you want.
Also, Canvas scale may help you for resizing ui objects,when you change screen size
This question already exists:
Closed 10 years ago.
Possible Duplicate:
Click and drag image to image grid?
I have a few image boxes in my form and I was wondering how can I would place a grid across the form that have a bunch of lines so the whole grid is a bunch of 64 x 64 squares. I need it so I can select an image and place it onto a specific square using the mouse and be able to go through the whole grid and check for example how many of one specific image is on the grid. To give you a better idea of what I'm doing is that I have a few image boxs which contain different 64 x 64 images. There is another image box that shows the image I clicked on last, which is like a brush because whenever you left click a box in the grid it pastes it into that specific box in the grid. I also need it so I can right click the box and delete the image in the box the mouse is over. Finally I need to be able to read all the images in the box and output it into a file that I can later open. I'm using it to create land in a game, which the program will output the needed texture and and where ground level is for the boxs which make up the whole terrain. What I need to know is what kind of thing should I do to be able to do this? I've been trying the past few hours on how I make the boxs and how to know where the mouse is and stuff and I'm completely stuck. A simple idea would be helpful. I actually don't know what control(s) I should use for this so an idea that doesn't involve any grid controls is still very helpful.
I don't know if it's the best possible idea, but you could use FlowLayoutPanel with WrapContent set to true and FlowDirection = LeftToRight. I dont know about Drag&Drop operation though (never done it with FlowLayoutPanel, buth there are some nice tutorials out there).
You can track your mouse position using mouse events. If you don't want to do that:
You can get absolute position at any time using:
Point currentPos = System.Windows.Forms.Cursor.Position;
Then, to get relative position on your (current) control:
Point relativeLoc = this.PointToClient(currentPos)
... and then, to get control over which your mouse is on FlowLaoutPanel:
Control c = flowLayoutPanel1.GetChildAtPoint(relativeLoc);
In my WinForms application I have Chart control with those settings:
chartArea.CursorX.IsUserEnabled = true;
chartArea.CursorX.IsUserSelectionEnabled = true;
chartArea.AxisX.ScaleView.Zoomable = false;
where chartArea is main (and only) ChartArea object in my Chart control.
What I am trying to do is posibility of selecting area (it is possible already), and when mouse is over this area, if I left click chart cotrol inside that selected area, I wan't it too zoom in.
First problem here is how to detect if I am over selected area ? with chart.HitTest() i can get HitTestResult.PointIndex field value and compare it with selection range. But this only works, if mouse is exactly over DataPoint. So it doesn't work for SeriesChartType.FastLine which I am using.
If this gets somehow solved, next will be problem with selection cancelation after mouse click (before Click or MouseXXX events are called).
SOLVED
I've found axis.PixelPositionToValue() method, which gives me every info I need, because from MouseMove event arguments I have pixel position.
For click events problem I'll write another question.
http://www.bigresource.com/VB-Using-MsChart-MouseOver-Event-to-display-the-contents-of-array-that-populated-chart-ydWJntrg8c.html
Though this is VB.NET, the concept is the same. I think.
I want measuring tool in project that will be same as measure it in Firefox (add-on). How to do this?
To get such a think to work you'll need an application that runs as a tray icon or something like that. Then you open your application and tell him, that you'd like to measure.
Now, you'll go and put a transparent window onto the whole screen(s) and wait for a mouse move event. Within the mouse move event, you'll check the mouse button state. If it is going to be hit you know the starting position and you can draw some kind of user-control at this position and if the user releases the mouse button, you're going to stop the resizing of your user-control.
The user-control itself should be semi-transparent and checking for the resizing and/or paint events, to draw the ruler lines around the border.
Last but not least you can show some kind of tooltip or labelcontrol in relation to the position and size of your user-control and screen bounds to give some status informations.
To get a good starting point about how to get the transparent overlay part done, you can take a look into ObjectListView Overlay.
--EDIT--
One solution could be:
Create a separate transparent windows form
Upon certain key press, for instance Ctrl+Shift+R, show your app with lower transparency level; so that user can see the background.
Draw ruler upon form load
You may allow user to move the ruler window with mouse click.
I am developing a small application with images and trash box icon on right hand bottom.
I have multiple images floating in the main window, and using mouse I can move image from one corner to other corner of window, left, right, top and bottom.
I can't figure out how do I catch an event when a image touches and panel (with trash box image), in the right hand corner.
Does anybody knows which event or handler to listen? This is not a drag and drop case since my images are floating so no point using drag and drop.
Thank you
Per this thread (MSDN), you could listen to an event fired when your image moves, and get Rects representing the trash box and the image, then use the IntersectsWith() method to detect if they are "touching".
Other than that, there are the UIElement events DragEnter, DragOver, and Drop (as well as their Preview___ counterparts) which might fit the bill. However, those are part of drag-and-drop. I'm not convinced that drag-and-drop is not appropriate in this situation. It sounds like drag and drop to me.