|
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.
|
|
|
|
|
Hello,
i created a test app in C#. i want to allow the user get his previous settings every time he run the program.(for example: if a user choose a number of keys for the test app as 32 keys. i want the user to see 32 keys already chosen for him the next time he run the program)
|
|
|
|
|
You can use configuration file (app.config). On this site are some nice articles about using System.Configuration namespace, search for them.
Easiest way would be to store settings as key-value collection in AppSettings, e.g
<AppSettings>
&add name="keys" value="32" />
</AppSettings<
Again, there is lot of examples out there.
errr, this is of course way in single-user environment, if you need to keep different settings for different users maybe try to keep config files in documents I know there is some app data folder (or similar) used for this very purpose.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
You have lots of options but simply you can write data to text or INI or XML files..
Save data while closing:
<br />
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)<br />
{<br />
WriteToFile(stringToWrite);<br />
}<br />
Read and apply settings on form load:
<br />
private void Form1_Load(object sender, System.EventArgs e)<br />
{<br />
ReadFromFile();<br />
ApplySettings();<br />
}<br />
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|