|
Form load would be a good place to put that snipet of code. That way it only runs once. If the code were to run twice you would get multiple calls to your button click event which would be very bad.
Ben
|
|
|
|
|
I pure GUI way would be to go to your form. Click on Button1 then go to the properties window. Click the lighting bolt this shows you the events for the button. Select the correct button click event. Repeat for other buttons.
Hope that helps.
Ben
|
|
|
|
|
I didn't get the methode of inserting code
and it not work if i put them in load form
but i try the second method to for the clickevent in the properties and it work
thank a lot
Assaf
|
|
|
|
|
Or you can just double-click the button
|
|
|
|
|
That works for the first event only. If you want to point the other two buttons to the same event you can not double click.
Ben
|
|
|
|
|
No, you click on properties, then the lightning bolt ( to show events ), find the click event, click in the box, click the drop arrow and select the method name.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
That is what I said in my earlier post. In my post you are responding to I said you can't double click to assign the same event to multiple buttons.
Ben
|
|
|
|
|
I would suggest that you create two simple projects, one in VB and the other in C#. In both applications you would have a form with three buttons. In VB have a method that handles the button clicks for the controls like what you have above. In C# you would assign the method to the click event of each of the three controls. Run the programs to make sure they do what you want. Then examine the IDE generated code, the code that contains all the event/control/layout declarations for VB and VC#. Compare what is similar/different with the two languages.
Hopefully this helps.
Regards,
Thomas Stockwell
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.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
I added a lot of ComboBox controls to WinForms form.
Every combobox shows all its content selected.
Selection is removed only when I tab off from the control.
How to hide selection initially?
There is not HideSelection property in Combobox.
This occurs if I set autocomplete properties.
class myComboBox : ComboBox {<br />
internal myComboBox(DataRow dr, DataTable table) {<br />
DisplayMember = "DisplayMember";<br />
ValueMember = "ValueMember";<br />
DataSource = lookup.GetPickList();<br />
DataBindings.Add("SelectedValue", table,<br />
dr["controlsrc"].ToString());<br />
AutoCompleteSource = AutoCompleteSource.ListItems;<br />
AutoCompleteMode = AutoCompleteMode.SuggestAppend;<br />
}}
Andrus
|
|
|
|
|
Have you found a solution to this? I am currently having a similar problem when binding a DataTable to my comboboxes...
|
|
|
|
|
No I havent found any solution to this .net bug.
Maybe it is possible to acces the underlyoing textbox which is contained in Combobox in combo constructor and set it HideSelection property to false.
Andrus
|
|
|
|
|
Hi all,
please i need the win32 API function to know the fact that is desktop changed.
Thank you in advance.
naresh is testing the site.
|
|
|
|
|
I'm not sure the exact answer, but anytime you are looking for a Win32 API function, you should check out the site http://www.pinvoke.net/.
Hogan
|
|
|
|
|
Thank you very much guys.
i look around your hints and links.
hope it works.
naresh is testing the site.
|
|
|
|
|
Hi,
what changes on the desktop ?
AFAIK:
- the resolution, the pixel depth, ... that will fire a Paint event; see also
the SystemEvents class.
- the icons (new, renamed, moved,...): no event available
- the background image: no event available
Hope this helps
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Actually i need to send the image of my desktop to remote computer whenever desktop gets changes. So for this, the i am expecting a common event(for opening new window on the desktop ,selecting the desktop area,minimizing and maximizing any window over the dekstop) that can be caught in my application and at the same time it sends the desktops changed image to the remote computer. So plz any body have any idea?? Actually i know there happens a Paint System event, if so how can i handle this event in my application to know the changed state of my desktop??
Thank you in advance!!
naresh is testing the site.
|
|
|
|
|
How does one receive events in a C# windows service from a COM object that has been instantiated from a background thread whose ApartmentState == ApartmentState.STA? I’ve been able to received events from the COM object in a WinForm app when the thread sits in a loop sleeping and invoking System.Windows.Forms.Application.DoEvents(), i.e. pumping the message queue.
The thread that accesses the COM object is responsible for responding to requests by other objects to access the COM object, done through a queue + AutoResetEvent, and for handling events raised by the COM object in response to those requests.
Other posts/web sites have mentioned that STA threads require a message loop/pump. It seems like if the thread that accesses the COM object were able to call a method that could sleep + message pump + respond to requests to wake up, I’d be set. Is there such a beast/can such a thing be created? Is this the right kind of design?
Thanks,
Steve
|
|
|
|
|
My understanding of windows services is they are not on the windows message queue, so it is doubtful you would ever be able to receive those messages.
Ben
|
|
|
|
|
With some help from a coworker, I figured out how to do this.
The message loop can be run on the same thread as the COM object using ApplicationContext and Application.Run. Other objects can communicate to the thread via Invoke on a dummy Control created on the message loop thread.
<code>
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace TestMessageLoopWindowsService
{
internal class TestMessageLoop
{
internal void Start(EventLog eventLog)
{
if (eventLog == null)
throw new ArgumentNullException("eventLog");
this.eventLog = eventLog;
Thread messageLoopThread = new Thread(MessageLoopThread);
messageLoopThread.Name = "Message Loop Thread";
messageLoopThread.SetApartmentState(ApartmentState.STA);
messageLoopThread.Start();
Thread invokeOnToMessageLoopThread = new Thread(Invoker);
invokeOnToMessageLoopThread.Name = "Invoker";
invokeOnToMessageLoopThread.IsBackground = false;
invokeOnToMessageLoopThread.Start();
}
private EventLog eventLog;
private void MessageLoopThread()
{
ApplicationContext context = new ApplicationContext();
control = new Control();
control.HandleCreated += new EventHandler(control_HandleCreated);
control.CreateControl();
Application.Run(context);
}
private Control control;
private void control_HandleCreated(object sender, EventArgs e)
{
okToInvoke = true;
}
private volatile bool okToInvoke;
private void Invoker()
{
while (true)
{
if (okToInvoke)
{
EventHandler method = new EventHandler(InvokedOnMessageLoop);
control.Invoke(method);
}
Thread.Sleep(1000);
}
}
private void InvokedOnMessageLoop(object sender, EventArgs e)
{
eventLog.WriteEntry("InvokedOnMessageLoop runs on " + Thread.CurrentThread.Name);
}
}
}
</code>
|
|
|
|
|
This isn't a specific programming question but more so a request for someone to explain the purpose of StringBuilder class?
Whats the difference between a char[] and stringbuilder? Can I access elements in a stringbuilder the same way as I would with an array?
|
|
|
|
|
Do you use char[] instead of string? You should use StringBuilder if you are having many manipulations on a string because StringBuilder is faster. You can access individual characters as you would do in an array
|
|
|
|
|
The StringBuilder is used when you have a lot of string manipulation, such as appending text inside of a loop. It's benefit comes from the fact that it doesn't need to create a new string instance each time it appends. Take the following loop:
string result = String.Empty;
for (int i = 0; i <= 10000; i++)
{
result += String.Format("i = {0}\n", i);
} Each time through this loop, you are allocating a new instance of a string to hold the concatenated value. Changing this loop to:
StringBuilder resultBuilder = new StringBuilder();
for (int i = 0; i <= 10000; i++)
{
resultBuilder.AppendFormat("i = {0}\n", i);
}
string result = resultBuilder.ToString(); you don't have all of the string allocations.
You can't access the value of a StringBuilder in any meaningful way other than to call it's ToString() method, which retrieves the internal value as a string . However, once you have it as a string , you could access the string by individual character positions just like you would a char[] .
Remember, string in .NET is not really equivalent to a char[] even though you can do a lot of the same operations; it is a first class data type.
|
|
|
|
|
Scott Dorman wrote: You can't access the value of a StringBuilder in any meaningful way other than to call it's ToString() method
Are you sure? As I have written in my post stringbuilder has a property called Chars so can access individual characters
|
|
|
|
|
You can certainly access individual characters out of the internal string value using the Chars property, but I have never run across a situation where that is really useful. Usually StringBuilder is used to save on string allocations when performing a lot of string manipulation with the end result desired being the final string value. By accessing it a character at a time, it isn't much different than building up a char array.
|
|
|
|
|
Scott Dorman wrote: By accessing it a character at a time, it isn't much different than building up a char array
It's dynamic, and one can Insert.
|
|
|
|