|
|
Hey,
I try to bind a datasource to my combobox. The datasource is an array of objects.
Then I set the cmb01.displaymember = "Propertyname1".
Till here everything works fine.
But then I will also set the valuemember like this :
cmb01.ValueMember = "PopertyName2".
At runtime I receive always following exception :
"Could not bind to new display member. Parametername is newdisplaymember"
What will this mean? And how I have to resolve it?
Tkx,
Jac
|
|
|
|
|
I am trying to figure something out. I have a panel control that contain other controls (I think, I am looking at some one elses code) but for some reason, I can't see the other controls. I can go to the properties window (the dropdown) and select them but I can't see them on my screen (they won't even highlight if I select them in the property dropdown). I right clicked on the panel control, and menued the "send to back" but nothing happens. Also sometimes, just sometimes all the controls do appear and then for some reason (unknown at this time) the all..... disappear...
Anyone?
Ralph
|
|
|
|
|
If you really want to know if the Panel contains those other controls, quick looking at the designer and look at the code. Every Control has a Controls property that contains a collection of Control s that are children of thet parent Control .
The other possibility is that there is some owner-drawing problem. Is this code overriding OnPaint or handling the Paint event on the Panel ? Somewhere in the initialization code, is the code using SetStyle to set styles incorrectly or overriding CreateParams (if a derivative class)?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I'm trying to achieve inter-thread communication in C# and am having a few problems. In MFC/C++ for 'GUI' threads I achieved the same aim by using PostThreadMessage. Am I right in thinking that events are the way to go? I understand them and don't have a problem when in a single threaded application, but extending the principle is proving problematic.
Any suggestions? Am I on the right track?
Alastair
|
|
|
|
|
EDIT: When you spoke of "events", I assumed your were referring to the classes in System.Threading. If this is not what you meant (if you meant events like delegate/event), then ignore what I say about "Events".
What type of inter-thread communication are your trying to do?
Events are not quite as powerful as a PostThreadMessage. PostThreadMessage allows you to send some information. Events are things you have one thread wait for (or poll for). You would have to create an Event for each type of message you wanted to wait (or poll) for.
You're not restricted to synchonization objects for communication. You can always have threads call functions on other classes. This gives the most flexibility (the parameters can be whatever you want). If you go that route, you'll need to make your methods thread-safe (using Mutex's or the lock keyword).
If you can, give me an example of what you're basically trying to do. Is it one main thread spawning many worker threads and waiting to hear back from each one when it has something to report? A small break down would help me give better advice.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
Hi David,
Thanks for your feedback. I'll try to give a concise and accurate explanation of what I'm trying to do. When I referred to events in my original post I did mean delegates.
In MFC I wrote a generic subsystem in which there existed the notions of Senders, Receivers, Messages, and the global messaging system (a singleton) which took care of passing on events of interest to appropriate parties (Receivers). Forget about Senders, that was a construct just to facilitate some nuance. So the important things are Receivers and Messages. Receivers are full blown classes which are doing some work within the system. Messages are also classes in their own right, and the nub of the system was that any receiver could register interest in any message, in particular specifying a function on the receiver class itself which would be invoked when that particular message was broadcast by some other object in the system. The whole thing hung together with a load of templated classes, functions etc. This system is a variant of Subject-Observer/Multicast.
Of course in C# we have beautiful constructs (like Java) such as retrieving all the methods for a given type, which makes life much easier because you can invoke a method against a particular object which was much more difficult in C++ for reasons I won't go into here.
Anyway, in C++ the global messaging system singleton executed in its own thread, and when some object wanted to broadcast a message they would obtain a lock on the singleton, call a method to broadcast said message and the singleton would then propagate this message to all interested objects by queueing the message for each thread, the singleton would then use the PostThreadMessage to indicate to the thread that messages were waiting for it, and when the thread received the context and the method referred to through the message map by the parameter to PostThreadMessage was executed, all messages queued up for that thread would then be propagated to the appropriate objects.
So what I was hoping to gain from the delegates/events was that I would be able to fire an event from the singleton to all threads and that an object within each thread would respond to said event and then retrieve all messages queued for objects instantiated within the context of their thread.
Am I going in the right direction do you think? I can supply a code example of what I'm trying if it would make things clearer.
Thanks,
Alastair.
|
|
|
|
|
A similar way is possible using an object-oriented framework like .NET. Instead of thinking procedurally, though, thing about how these objects react with each other, or with other objects.
For instance, you could code an event on the object that starts all the threads, for which they would handle. You should invoke these delegates attached to the event in an asynchronous manner, most likely. You could also add events to the threaded object but then the invoking class has to keep track of them and add and remove delegates. The first way makes more sense.
One thing that may help is that the C# compiler (I believe the VB.NET compilers does as well) generates synchronous (Invoke ) and asynchronous invocation methods (BeginInvoke , EndInvoke ). that are visible in the code editor when the delegates are declared in the current project. For more on asynchronous calls in .NET, see Including Asynchronous Calls[^] in the .NET Framework SDK.
It seem, though, like you are headed in the right direction. The only thing you have to watch out for is that you invoke the methods from the calling thread in the thread that contains the object.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Where is a discussion of the current and future optimizations that the C# compilers do? When I see things like the following I start to question my faith in csc being good at optimizing. (The same kind of thing shows up in cordbg when looking at the JIT code for a similar example.)
% cat y.cs
using System;
class A {
bool On { get { return true; } }
public void Print() {
if (On) {
Console.WriteLine("On");
}
}
}
class ConditionalTest {
static void Main()
{
A a = new A();
a.Print();
}
}
% csc /optimize+ y.cs
Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.
% ildasm y.exe
.method public hidebysig instance void Print() cil managed
{
// Code size 19 (0x13)
.maxstack 2
IL_0000: ldarg.0
IL_0001: call instance bool A::get_On()
IL_0006: brfalse.s IL_0012
IL_0008: ldstr "On"
IL_000d: call void [mscorlib]System.Console::WriteLine(string)
IL_0012: ret
} // end of method A::Print
%
At least the compiler eliminates the "if" test when "On" is replaced with "true" in the test.
|
|
|
|
|
Visual Studio has the nifty-looking selection colors when you hover over the main menu. I am in the process of writing a custom control, and I would like to use those colors (Windows Theme-depended obviously) for the selection mechanism in my custom control.
It seems System.Drawing.SystemColors isn't the proper way to get them; I can't find a SystemColor that is the correct color across all Windows Theme skins; for example, using the standard Blue Luna theme, SystemColors.InactiveCaptionText is the correct color for the internal region of the selection. However, using the Olive theme, that is not the correct color.
How can I get the correct colors needed to draw a VS-style selection?
Thanks ahead of time.
The graveyards are filled with indispensible men.
|
|
|
|
|
Sometimes Microsoft changes the normal colors of a control by changing the RGB components, like adding the difference between the current color and FF (for each component). This will lighten the color. There are also SystemColors that should already have such values, too, like ControlLight and ControlLightLight . You could try these as well.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
I wrote a program to go through all the SystemColors and compare them with what Visual Studio uses. The result was that there were some colors that Visual Studio uses (for instace, to draw a Visual Studio menu using the Luna Blue theme, SystemColors.Highlight can be used for the outer border, and SystemColors.InactiveCaptionText can be used for the inner region). However, if I switch themes, say to the Olive theme, SystemColors.Highlight and SystemColors.InactiveCaptionText no longer are the correct colors. In addition to checking all the SystemColors , I've also check through all system colors put through ControlPaint.Dark , .DarkDark , .Light , and .LightLight and still haven't found the correct colors!
Ack.
The graveyards are filled with indispensible men.
|
|
|
|
|
As I mentioned before, another thing they sometimes do is modify the RGB components of the color to get such an effect (adding to lighten, subtracting to darken). You could do the same thing if the SystemColors don't work for you.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Does anyone know how to programmatically position the mouse on a control in c#?
Darryl Borden
Principal IT Analyst
darryl.borden@elpaso.com
|
|
|
|
|
Cursor.Position = somePoint;
If you want to limit that point to be on the control, use the control's .PointToClient method. For example,
Point somePoint = new Point(0,0);
Cursor.Position = myControl.PointToClient(somePoint);
The graveyards are filled with indispensible men.
|
|
|
|
|
I am new to .NET. I have 1 solution with 2 projects. Project 2 compiles into a class library which is reference from Project 1. I wish to walk into the source of my reference during debug. Can I do this? BTW, both projects are set to debug...
Thanks
Ralph
|
|
|
|
|
Should work just fine...just set your break points and launch it.
|
|
|
|
|
Thanks but it doesn't. So here is a bit more info. Project 1 is a ASP.NET application, so I lauch a web page. I wish to trace into the method that is in the reference. So if I CAN'T trace into the method, what should I check...
Thanks
Ralph
|
|
|
|
|
Debugging has to be enabled on the server. In IIS, you can configure this in the Application Configuration. The .NET Framework debugging tools (from the SDK) also have to be installed (from what I've read), so install the SDK on the server (not just the runtime).
There is a lot of documentation on this in the KB at http://support.microsoft.com[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for all the help. I realized (later) that these were stubs, RPC calls to the server...
|
|
|
|
|
hi all
I want to trace the parallel port & serial port
thanks;)
|
|
|
|
|
|
|