|
Hmmm,
I don't understand why you are doing that!
You said that you whant it to show when the user clicks the control.
So I would rather use the click or mousedown event of the combobox.
Hope it helps!
All the best,
Martin
|
|
|
|
|
No Martin,
I want to prevent the combo from showing the dropdown (the reason is that i'm doing something else instead of showing the list).
I think I'll just fake it with an edit & a button.
|
|
|
|
|
Ohh,
Than I missunderstod what you actually wanted to do.
I made a little test project for you, which is doing:
The dropdown box should be shown if the left mouse button is clicked, but not if the right mouse button is clicked.
I'm using the mousedown event for that.
private System.Windows.Forms.ContextMenu emptymenu = new ContextMenu();
private System.Windows.Forms.ContextMenu oldmenu;
private void button1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
if(button1.ContextMenu!=emptymenu)
oldmenu = button1.ContextMenu;
button1.ContextMenu = emptymenu;
}
else if(e.Button == MouseButtons.Left)
{
if(oldmenu!=null)
{
button1.ContextMenu = oldmenu;
}
button1.ContextMenu.Show(button1, new Point(e.X,e.Y));
}
}
Hope it helps!
All the best,
Martin
|
|
|
|
|
On my web form I have a text box, that when the form loads it get a string of text from a MySQL database and set the text box property as the string.
So then you can edit the text.
Then I have a button next to it that when you press it should put the text in the text box in to the database.
But it never changes the information in the database.
I think the problem might be to do with when I press the button it refreshes the page, therefor resetting the information in the text box and putting the original text back in to the database.
Any help will be very much appreciated
Thanks.
|
|
|
|
|
I am guessing that your onLoad event is always populating the text box. I think you may want to use the IsPostBack to see if you are doing a page load from your button click. So you only set the data from the text box if !IsPostBack or Not IsPostBack in VB.
Hope that helps.
Ben
|
|
|
|
|
Is there a way to control which monitor a winform will be opened on?
Thanks.
|
|
|
|
|
Hello,
It's just a question of where you set the Forms Location and which resolution you are using on the monitors.
All the best,
Martin
|
|
|
|
|
Use class System.Windows.Forms.Screen.
Geniality is in simplicity.
|
|
|
|
|
Thanks Martin and Jakub, I got it.
|
|
|
|
|
hi ...
i need a good ebook for starting mobile programming in C#
thank you ...
|
|
|
|
|
When i click with the right mouse button shows the contextmenu.
How to do this with the left mouse click.
C#
|
|
|
|
|
Hello,
Here I made a code example for the mouse down event on a button.
private void button1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
if(button1.ContextMenu!=null)
{
button1.ContextMenu.Show(button1, button1.Location);
}
}
}
Hope it helps!
All the best,
Martin
|
|
|
|
|
But the contect menu appears on other location.
I want it on the location where is the button.
C#
|
|
|
|
|
Hello,
This will set the menu starting location in the middle of the button.
button1.ContextMenu.Show(button1, new System.Drawing.Point((button1.Width/2), (button1.Height/2)));
All the best,
Martin
|
|
|
|
|
Can someone tell me how to set the menu at the mouse position.
C#
|
|
|
|
|
Hello,
You have to use the EventArgs properties "X" and "Y"!
private void button1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
if(button1.ContextMenu!=null)
{
button1.ContextMenu.Show(button1, new System.Drawing.Point(e.X, e.Y));
}
}
}
All the best,
Martin
|
|
|
|
|
button1.ContextMenu.Show(button1, Cursor.Current.Position);
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thanks for helping me.
C#
|
|
|
|
|
Hello Stefan,
Stefan Troschtz wrote: button1.ContextMenu.Show(button1, Cursor.Current.Position);
I assume that this was out of your head without testing and in big hurry.
Because it's not compiling (at least not in framework1.1).
I think what you meant was:
button1.ContextMenu.Show(button1, Cursor.Position);
But this is also not the right solution because the position of the contextmenu is relative to the button location. So you would have an offset depending on the position of the form.
I think only the eventarg members X and Y are giving the right location, without an additional calculation of offsets.
All the best,
Martin
|
|
|
|
|
Martin# wrote: I assume that this was out of your head without testing
Almost true. Did not test, but got it from the docs whereby I oversaw that Position is a static property too.
Martin# wrote: But this is also not the right solution because the position of the contextmenu is relative to the button location. So you would have an offset depending on the position of the form.
In fact, the Position property returns screen coordinates so unless the button is in the upper left region of the screen one probably cannot see the context menu. I must admit I didn't thoroughly read the documentation of the ContextMenu.Show method, so I missed that the point you're passing in has to be relativ to the location of the passed in control.
Martin# wrote: I think only the eventarg members X and Y are giving the right location, without an additional calculation of offsets.
You're right. Using Cursor.Point would require an additional call to the Control.PointToClient method.
Overall, a quite lousy post of mine Thanks for the addition.
Regards, Stefan
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Stefan Troschtz wrote: Overall, a quite lousy post of mine
Don't be so hard with yourselve.
All the best und noch einen schönen Tag!
Martin
|
|
|
|
|
Can anyone help me to create Gantt chart using C#. The Gantt chart need to be dynamic which mean the chart can be drag and drop.
|
|
|
|
|
What you request is to complex to be answered in a forum post. You need to break your problem down in to managable components first.
|
|
|
|
|
The gantt chart will generate bar and the bar can be move by mouse click to drag anywhere in the chart
|
|
|
|
|
You really need to break it down further than that. Break it down in to smaller and smaller steps until you almost have the code you need to get this to work.
|
|
|
|