|
xjsun wrote: I understand it's from another thread, but only this AllowDrop cannot be modified. Other properties can be changed without any problem. Do you know why is that?
Not a clue. That is strange. Which version of Visual Studio are you using?
xjsun wrote: From the articles I read, it's the right way to modify GUI through callback thread...
Hmm, interesting! I would have thought that since the callback is running on a different thread, via the delegate's BeginInvoke method, that it would be prohibited from modifying the GUI, but there must be some things here I'm not aware of.
xjsun wrote: I cannot think any other better way since I don't want to block the GUI in anyway.
I can understand that. And it rules out suggestiong that you use the Form's BeginInvoke method because it would marshal the delegate invocation to the GUI's thread.
Sorry I can't be of more help.
|
|
|
|
|
xjsun wrote: From the articles I read, it's the right way to modify GUI through callback thread
No, this[^] clearly says that
There are four methods on a control that are safe to call from any thread: Invoke, BeginInvoke, EndInvoke, and CreateGraphics. For all other method calls, you should use one of the invoke methods to marshal the call to the control's thread.
I have a strong suspicion that that is what is causing the problem.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thanks Senthil,
I am sorry that I don't really get what you mean here. Would you please be more specific about it? Thanks.
By the way, I want to clarify little bit here. The test program I posted initially is not exactly what I am using in the application, but it does generate the same problem. In the application, I call the delegate from another thread (not from a button). From the thread, I want to update certain GUI things and this is waht I found how to do it. Are you saying this is not right way of doing it?
Thanks again for the help.
John
|
|
|
|
|
Whenever you need to update a control or form from another thread, you have to use the control's or form's Invoke or BeginInvoke methods. Say you have an event handler in your form that gets notified from another thread. To make it thread safe, it might look something like this:
private void SomeEventHandler(object sender, EventArgs e)
{
if(InvokeRequired)
{
EventHandler handler = new EventHandler(UpdateControl);
Invoke(handler, new object[] { e });
}
else
{
UpdateControl(sender, e);
}
}
private void UpdateControl(object sender, EventArgs e)
{
someLabel.Text = "Some event occurred.";
}
Applying this to your callback, you would check the InvokeRequired property in the callback, and if it is true, you would use the form's Invoke or BeginInvoke to invoke a delegate on the same thread as the GUI in order to modify the form's control. I really don't know of any other way of doing this. That's why your comment about reading some articles that showed a different way threw me off.
I don't think you have to worry about blocking the GUI very much here. True the callback will eventually get handled on the same thread as the GUI, but for simply setting a control property, it shouldn't take any noticable time at all. Hope this helps.
|
|
|
|
|
I think this is what I am missing. I knew I have to use delegate to callback from a thread to the GUI thread but I certainly missed this part. Thank you all for the greate help!
John
|
|
|
|
|
Consider the following code:
public class A
{
private int x = 0;
public int X
{
get
{
return x;
}
set
{
x = value;
}
}
public override string ToString()
{
return x.ToString();
}
}
public class B
{
private ArrayList list = new ArrayList();
private void addItem( A c )
{
list.Add(c);
}
private void changeItem ( ArrayList l )
{
((A)l[0]).X = 5;
}
public void test()
{
addItem( new A());
Console.WriteLine(list[0]);
changeItem(list);
Console.WriteLine(list[0]);
}
public static void Main( string[] args )
{
B b = new B();
b.test();
}
}
The output is:
0
5 Why the output not like:
0
0 changeItem method does not take the reference of the ArrayList, but the value of the object in the collection has changed What is the problem ?
|
|
|
|
|
Kamrul Hasan wrote: changeItem method does not take the reference of the ArrayList, but the value of the object in the collection has changed What is the problem ?
Actually, changeItem() is taking the reference to your ArrayList member variable. Look again in your test() code. You're passing a reference to ArrayList member variable "list" into changeItem().
<br />
public void test()<br />
{<br />
addItem( new A());<br />
Console.WriteLine(list[0]);<br />
changeItem(list);
Console.WriteLine(list[0]);<br />
}<br />
|
|
|
|
|
Thanks for your reply.
In which cases 'ref' keyword should be used? I am confused
As your answer the following two methods will do the same thing isn't it?
1.changeItem( ref ArrayList l )
or
2.changeItem( ArrayList l )
|
|
|
|
|
Member variable "list" is a reference to the ArrayList object and not the object itself. The important thing you need to learn here is the difference between "reference types" and "value types".
All classes such as ArrayList are reference types. Class objects are created via "new" and they only exist in the heap (not the stack). "new" merely returns a reference to that new object. So, when you pass an object reference to a function, you are merely passing a copy of that reference and not a copy of that object.
All structures such as int, long, and float are value types. These types are created on the stack and are not referenced. And yes, they really are structures. int maps to the System.Int32 structure. float maps to the System.Single structure.
So, when you pass a value type into a function, you are passing a copy of its data.
I'm not sure what your goal is here, but if you want to pass a copy of your ArrayList object into your changeItem() function, then you're going to need to clone it. Cloning an object will create a new object having the same object data.
changeItem((ArrayList)list.Clone());
I hope this helps!
|
|
|
|
|
Just in case the OP misses it, only the ArrayList is cloned, not the elements in that list.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Since the ArrayList contains integers (ie: value types), it should be copied ok.
But good point to bring up. If it stored reference types, then they'll need to be cloned too.
|
|
|
|
|
Is there any way to group several radio buttons without putting them into a GroupBox ?
|
|
|
|
|
You can only have one grouping of RadioButtons per Form, GroupBox, or Panel. If you want to have several groupings that look like they're on the same form, then I suggest you put them inside borderless Panels.
|
|
|
|
|
Set the Groupnames same with the other radiobuttons
<asp:radiobutton id="RadioButton1" style="Z-INDEX: 101; LEFT: 256px; POSITION: absolute; TOP: 184px"
="" runat="server" <b="">GroupName="a">
<asp:radiobutton id="RadioButton2" style="Z-INDEX: 102; LEFT: 256px; POSITION: absolute; TOP: 224px"
="" runat="server" <b="">GroupName="a">
<asp:radiobutton id="RadioButton3" style="Z-INDEX: 103; LEFT: 440px; POSITION: absolute; TOP: 192px"
="" runat="server" <b="">GroupName="b">
<asp:radiobutton id="RadioButton4" style="Z-INDEX: 104; LEFT: 448px; POSITION: absolute; TOP: 232px"
="" runat="server" <b="">GroupName="b">
|
|
|
|
|
Hi,
Anybody have any ideas on how to best emulate a 'ReadOnly' capability for a radio button? Any help greatly appreciated.
|
|
|
|
|
Enabled = false
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
I'm doing that already. Looks like sh*t.
|
|
|
|
|
Your problem statement is not clear. Can you explain it a bit more ?
|
|
|
|
|
Hi,
Thanks for your interest. I have a data application in which some boolean choices as represented by radio button pairs and at certain points in the application I am representing the data to the user in ReadOnly TextBoxes where applicable. I would like to emulate this functionality in a representation of the RadioButton and am looking for a path of least resistance to accomplish this task. Any help would be greatly appreciated.
|
|
|
|
|
Change the font color back to black after disabling the button?
|
|
|
|
|
I've taken a different approach by building my own custom control that inherits from System.Windows.Forms.RadioButton NameSpace. I'm using GDI+ to alter the presentation of the interface based off a boolean public property I've exposed called 'ReadOnly'. I'm still trying to workout how to cancel 'Click' the click event. Any help would be greatly appreciated.
|
|
|
|
|
You can stop the click Event by overriding the OnClick method in RadioButton class and Removing the call to the base class. like:
protected override void OnClick(System.EventArgs e)<br />
{<br />
}<br />
-- modified at 12:27 Monday 14th November, 2005
|
|
|
|
|
Hi, and thanks for your interest. I tried your suggestion but when I tried to build the control I received an error 'RadioButtonRocLib.RadioButtonRoc.onclick(System.EventArgs)': no suitable method found to override".
|
|
|
|
|
correct code is:
<br />
protected override void OnClick(System.EventArgs e)<br />
{<br />
}<br />
Here 'OnClick' 's 'O' and 'C' character should be in upper case. I don't know why it is not shown correctly.
|
|
|
|
|
Hi,
I have a little problem with a networkapplication i'm creating at the moment. I'm making a program where a windows service (in C#) sends information (username etc) to a java server. I have done some research allready for getting the current username in Windows:
WindowsIdentity temp = WindowsIdentity.GetCurrent().Name;
Now my problem is that i don't receive a logonname on my java server. Instead of that i get the following:
NT AUTHORITY\Lokale service
I tried some other examples (importing dll's etc) for getting the username but always gets the same reply. I really dont know how i can solve this. Does anyone has an idea what went wrong? You would help me alot...
Greetings
Steven Bruneel
|
|
|
|