|
If the form & control creation threads are different, then the event on the other thread have to be invoked. Adding a child control from a different thread fires events on the new parent thread that should be invoked. Obviously, you don't have control of the firing to make them invoked, so crash and burn.
The child draws fine, the parent, needing invoke, crashes.Opacity, the new Transparency.
|
|
|
|
|
When I began testing, that was my assumption going in. However, of the three code snipplets I posted, two work fine, which seem to counter your explaination. A .NET control parented to a native Win32 window in a separate process works fine as well as a .NET "UserControl" class being parented to a .NET window in a separate process. Only in select cases does your explaination seem to hold weight. Try my examples and see what you get.
|
|
|
|
|
I have a recollection that user control is special in some manner, and pointing in that direction, from MSDN:
You can host Windows Forms UserControl derived classes inside of a form, on another UserControl,
inside of Internet Explorer on a Web page, or inside a WebBrowser control hosted on a form. [^]
I have not used user control myself, but I have hit the multiple thread problem you are talking about with other controls.
I recall the solution we had used was 'single threaded apartment' vs 'multiple threaded apartment', but I can't remember which worked correctly. I think it was single threaded, but try both and see if it changes.
Or try creating a usercontrol with a button in it and moving it to the other thread. User control may fix the threading problem for its children.
Either way, let me know how it comes out.
Thanks
RichardOpacity, the new Transparency.
|
|
|
|
|
The only thing special about the UserControl1 class is that I changed the background color. I could have used the UserControl class directly and set the background color. It makes no difference. In several test cases, I even added several buttons and other controls onto my derived UserControl1 class. It still works fine as a child to a Win32 or .NET WinForm in a separate process. I have learned that when ever a window (or control in .NET terms) posts a message via PostMessage(..), the active thread just adds the message to the destination's message queue and returns immediately, not waiting for the message to be processed. Had I posted a message via SendMessage(..), the active thread would suspend until the message is processed. My guess is that some of the .NET controls (like the Button control) uses SendMessage(..) somewhere internally and waits for it's child/parent to process, perhaps creating even a deadlock somewhere in worse cases. I have found articles and forums suggesting the CLR might be disposing a handle to GDI objects a the point where the exception is thrown in the internal paint procedure or the GDI handle count is exceeded. Eitherway, I am puzzled. I have found articles and code showing multithreaded windowed applications to work fine, but most developers usually have no need for such and never investigate.
|
|
|
|
|
That makes sense.
I don't know where I heard or read about UserControl being special, but this reinforces it.
I'd say that they did decouple cross thread calls in userControl.
We have an app that every window has a thread that actually creates and opens the form.
It also makes tabs by taking the contents of an existing form and sticking it into a new TabControl.
Don't ask why, it's a long story
While we were initially working on it, we would get cross thread exceptions.
We changed some of the windows to be single threaded apartment, and the problem went away.
We were having problems with the clipboard that also went away when we did STA.
This should also may help me. We are doing much to deal with this problem is other areas. UserControl as the top level container looks like it could let us get rid of some code.
Thanks
RichardOpacity, the new Transparency.
|
|
|
|
|
hii all
m new to windows application.I want to create a desktop application but dont have idea
where to start with.Can anybody give me any gud link or tutorial or name of ebooks which would
help me in my project.however i have worked on web application(asp.net using csharp).plz guide me ...thanks..
|
|
|
|
|
You could check out any one of the results here:
Windows Forms Application Tutorials[^]
or search for the MSDN videos.I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
Download Visual C# 2008 Express Edition.
http://www.microsoft.com/express/Downloads/#2008-Visual-CS[^]
Install, launch, and register (Help -> Register Product). After you register, you'll be eligible for some freebies, including the book (PDF) "Microsoft Visual C# 2008 Express Edition - Build a Program Now!". Download that, and it should help get you started.
|
|
|
|
|
You could start by going through some good C# books.Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
can u suggest some books based on win applications
|
|
|
|
|
Well... I load from database some tables in comboboxes. I want to display only a part of data (i work with adress (state, region, street, cp etc.)) so i use local datasets and load all of it in combobox with arraylist (datasource, displaymember etc.). But i can't just register every street in the country, so for a special place i register all of it, and for all other i want to make possible to register it if it's not registered. So i need to check if i write in combobox some text and then want to insert it in the database if this text is already in the combobox displaymember. So how can i search for an item in combobox by displaymember text?
|
|
|
|
|
Please do not post the same question in multiple forums. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
I have a login form which will connect the Active Directory to check the user; but the output that i get is alway not couldn't connect.
Boolean Success = false;
DirectoryEntry Entry = new DirectoryEntry("LDAP://" + Domain, UserName, Password);
DirectorySearcher Searcher = new DirectorySearcher(Entry);
Searcher.SearchRoot = Entry;
Searcher.Filter = "(&(objectClass=user)(sAMAccountName=" + UserName + "))";
Searcher.PropertiesToLoad.Add("cn");
Searcher.SearchScope = SearchScope.Subtree;
try
{
//Test = UserExists(Domain, UserName, Password);
SearchResult Results = Searcher.FindOne();
Success = (Results != null);
}
please help me to find the solution.Regards,
John.L.Ponratnam
|
|
|
|
|
Hello everybody,
I'm developing a custom control containing a TreeView control and a couple of buttons and etc ...
Now, the question is that how can I show the smart tags menu of the TreeView at the design time?--------------
Vahid Rassouli
|
|
|
|
|
Ours is a desktop application (windows based) and based on remoting distributed architecture.
It is a windows based application and not web based.
Steps followed to run the application
1. Application is deployed / hosted on Citrix Server.
2. User has to first logon to citrix server.
3. User clicks the icon of the application in Citrix Server.
Question is
1. If IIS is running, could it mean that underlying channel is HTTP, or could it be
that remoting is done using TCPChannel itself
2. I know that IIS is a web server for ASP.NET web application, why is IIS being used
for a windows application.
3. What could be the role of IIS / Worker process in a desktop or windows application?
4. important!!! Is it that Citrix works as a fileserver also. I am asking because
files are not maintained in the client machine, so when user clicks the icon
in citrix, does necessary DLLS get loaded in the client machine firstly?
Regards,
NetQuestionsmodified on Friday, February 19, 2010 1:29 AM
|
|
|
|
|
Doesn't the use of IIS completely rule out the use of TcpChannel. The communication should be using HTTP and SOAP and not
using Tcp sockects?
Regards,
NetQuestions
|
|
|
|
|
NetQuestions wrote: If IIS is running, could it mean that underlying channel is HTTP, or could it be
that remoting is done using TCPChannel itself
That depends on your remoting configuration. Did you tell your app to use HTTP or to use Sockets to talk to the remote object?
NetQuestions wrote: 2. I know that IIS is a web server for ASP.NET web application, why is IIS being used
for a windows application.
What makes you think it is? Did you have a remote object or a webservice being hosted by IIS?
NetQuestions wrote: 3. What could be the role of IIS / Worker process in a desktop or windows application?
None at all.
NetQuestions wrote: 4. important!!! Is it that Citrix works as a fileserver also. I am asking because
files are not maintained in the client machine, so when user clicks the icon
in citrix, does necessary DLLS get loaded in the client machine firstly?
That depends entirely on how your application is configured in Citrix. If your streaming the app to the client, then the app gets sent to the client and run there. If app is configured to run on the Citrix server, then all that's sent to the client is the window images of the application.
There are, of course, more options for all of these questions, but your not providing enough details on the background of any of these questions to answer them with anything other than generalities.
See what I'm getting at here? Your questions are all answerable, but only by you because all of this stuff in under direct control of how you designed your app, what remoting configuration you've chosen, how the app was deployed to the Citrix server, and how it's being setup and advertised in Citrix.
|
|
|
|
|
thanks dave. I shall get back to you.
regards,
NetQuestions
|
|
|
|
|
Colleagues,
Is there a standard (and free) control which is like a ComboBox, only better? Some of the potential features could be:
* being able to control the font for each of the items individually
* icons, checkboxes next to the items
If such thing exists, could you post a reference? If not, then I’ll stop the wishful thinking and carry on with the standard ComboBox.
Cheers,
- Nick
|
|
|
|
|
You may like to investigate WPF where it is relatively easy (after the steep learning curve) to create such controls yourself. Take a look at some of the WPF articles here on CodeProject to see the sort of things that can be done. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Hi,
ComboBox (as well as ListBox):
1. holds and shows items of any type you choose, not just strings.
2. supports "user drawing", see DrawMode property and DrawItem event.
Hence you could:
- define your own little class representing such item, with all the properties you'd like;
- paint it yourself in whatever format you like.
I often do this with ListBox, and occasionally with ComboBox.
And no, I don't have a published example around.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
You might want to subclass the combobox and add your own functionality as shown here[^].Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
Using VB 2008 and a simple MDI application...
When the active mdi child is maximized, there is a small gap between the right side of the child and the right side of the parent. Admittedly not a life-altering problem but it is worrisome. Anyone know of a fix?
|
|
|
|
|
Hi,
Please forgive me as this may be a very simple question but I am a newbie at this. I have searched for this info for three days now and cannot seem to find any answers. I have two questions:
Q1. How do I reset the background color of a push button.
I have a standard button. In the code snippet below I also have a cursor style change. The cursor changes back to the original (default cursor) when the mouse leaves the button (without me including any cursor specific code in the MouseLeave function) but the back color does not change. I even tried to set up a pointer to store the original color and this works but after the mouse leaves the button the style of the button is chnaged to flat. Do I need to also store the FlatStyle and retrieve it on MoudeLeave?
// declare an int pointer (for the exit button background color) called
btnExit_default_BackColor
int *btnExit_default_BackColor;
// declare a boolean pointer (for the exit button UseVisualStyle background color) called
btnExit_default_UseVisualStyleBackColor
bool *btnExit_default_UseVisualStyleBackColor;
private: System::Void btnExit_MouseEnter(System::Object^ sender, System::EventArgs^ e) {
// allocate memory for an int variable and make the btnExit_default_BackColor pointer
point to this new memmory
btnExit_default_BackColor=new int;
//assign the exit button background color to the memory allocated
*btnExit_default_BackColor=btnExit->UseVisualStyleBackColor;
// allocate memory for a bool variable and make the btnExit_default_UseVisualStyleBackColor
pointer point to this new memmory
btnExit_default_UseVisualStyleBackColor=new bool;
//assign the exit button background color to the memory allocated
*btnExit_default_UseVisualStyleBackColor=btnExit->UseVisualStyleBackColor;
btnExit->Cursor=Cursors::Hand; // change mouse cursor to hand when over a push button
// Change button outline color to 0x00FF4500 (orange red with opacity 0)
System::String^ highlightColor="#0x00FF4500";
btnExit->BackColor=System::Drawing::ColorTranslator::FromHtml(highlightColor);
}
private: System::Void btnExit_MouseLeave(System::Object^ sender, System::EventArgs^ e) {
// Change button outline color to original state before mouse hover
btnExit->BackColor=System::Drawing::Color::FromArgb(*btnExit_default_BackColor);
btnExit->UseVisualStyleBackColor=*btnExit_default_UseVisualStyleBackColor;
delete btnExit_default_BackColor; // delete the btnExit_default_BackColor pointer
delete btnExit_default_UseVisualStyleBackColor; // delete the
btnExit_default_UseVisualStyleBackColor pointer
btnExit_default_BackColor=0; // set pointer to null
btnExit_default_UseVisualStyleBackColor=0; // set pointer to null
}
This seems very complicated for what I think is a very simple thing. I just want the color of the button to chnage when the mouse is over it and have the button revert to its original (design) state when the mouse leaves. Can someone please help me with this. Thank you very much in advance for any help you may be able to provide.
Q2. Can someone please explain to me the funcion of the ^ in the parameter list of the functions above; i.e. in
private: System::Void btnExit_MouseLeave(System::Object^ sender, System::EventArgs^ e) {
I cannot find any reference to this operator. The closest I have come is that it may be a top-level reference but I don't know what this means and how it works,
Please forgive if these are too simple questions. Thank you.
Paul
|
|
|
|
|
I can't answer your first question but I can explain the ^ operator:
That operator is a reference to a managed object.
So, if you have
void btnExit_MouseLeave(System::Object^ sender, System::EventArgs^ e)
That means that the function takes a reference to a System:Object and a reference to a System::EventArgs object.
If you have Object* obj , it means that obj points to the object on the heap.
In the same way, the ^ means that the variable points to the object on the managed heap.
The ^ is used with the gcnew operator to assign a new object instance to a variable, as in:
Object^ var = gcnew Object()
|
|
|
|
|