|
Hi, I created custom control derived from UserControl and added a button on it.And I added a second button and docked it to the first button.
Question is: When the first button draws/paint well at runtime, the second button sometimes is absent, not visible. It only shows up when mouse enters the invisible area
Thanks in advance
|
|
|
|
|
It works fine for me. You haven't provided any details about how this control is setup, how it's drawn, if you're using any threading, if you're painting stuff on the control yourself, ...
|
|
|
|
|
Hi,
I need to design a program should be able to update certain textbox for each event inside the GUI and after every 10 seconds of most recent event, text tox should be back to original value..Let say
<br />
Event one occurs --> text box updated --> after 10 seconds --> text box back to normal
This is the case in perfect world, but it might be possible that someone create another GUI event during this period of 10 seconds..
Event one occurs --> text box updated --> after 8 seconds --> event two occurs --> GUI updated --> after 2 seconds the other thread (10 seconds completed for first event), text box back to normal.
So in this case, for second event, the textbox get back to original value in just 2 seconds. I know I could use thread intrupt to cancel the other thread. But my question is, it the best way of doing it?? And what is there any other way to starting intrupped thread again, without making a new thread? Will thread intrupt make sure everything will go perfect?? Would you suggest some more efficient way? I may be misunderstanding about threading here, please forgive that. Any suggestions, links or comments will be appreciated.
PS
So far my code is like this..
Thread t = new Thread(keep_run);
public void update()
{
t.Interrupt();
if (MessageLbl.InvokeRequired)
{
MessageLbl.Invoke(new setText(() => MessageLbl.Text = "User settings have been updated."));
}
else
{
MessageLbl.Text = "User settings have been updated.";
}
t = new Thread(keep_run);
t.Start();
}
private void keep_run()
{
try
{
Thread.Sleep(10000);
MessageLbl.Invoke(new setText(() => MessageLbl.Text = "Welcome to MAT Downloader"));
}
catch { MessageBox.Show("Interrupted"); }
}
}
If you find any other problems with the code then do mention them.
Thanks
Regards,
Shivam Kalra ![Smile | :)](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
Is it really necessary to resort to threads here?
And if the answer is yes, then more specifically, is it really necessary to resort to multiple GUI-altering threads?
Why not just make the main (GUI) thread have a method that updates the text box and a Timer control that triggers after 10 seconds to reset the contents of the text box.
When a new text-event occurs, your method is called again, and you reset the timer to 10 seconds again.
Something in the way of (incomplete code):
void AddNotification(string NotifyText)
{
Timer1.Enabled = false;
MessageLbl.Text = NotifyText;
Timer1.Enabled = true;
}
void Timer1_Timer(object sender)
{
Timer1.Enabled = false;
MessageLbl.Text = "Default text here";
}
With Timer1's timeout set to 10 seconds. If your GUI thread is doing some intensive work, then the timer might not fire until after the work is done. If that is a problem, thát would be the time to use threads, to do the work in a background thread while the GUI remains responsive.
All in all, it's best to have the main thread handle all GUI.
|
|
|
|
|
So I have a code to connect to NamedPipeServerStream, code works fine but after closing the Form, Connect never throws exception and Application do not ends.
void BeginConnect()
{
new Thread(new ThreadStart(delegate()
{
NamedPipeClientStream client = new NamedPipeClientStream(".", "testpipe", PipeDirection.InOut);
try
{
client.Connect(5000);
}
catch (TimeoutException ex)
{
}
catch (IOException ex)
{
}
BeginConnect();
})).Start();
}
One more thing, why this simple code taking more than 50% CPU
edit :
Found a workaround, http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/7bbf5a0b-3c22-4836-b271-999e514c321b/[^]
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
modified on Sunday, June 26, 2011 12:17 AM
|
|
|
|
|
I have some LinkLabel controls in a Windows Form. When the user clicks a LinkLabel the application displays a form containing data pertaining to the object selected, determined by the LinkLabel's text. The form is not displayed as a dialog and it is not maximized by default. The behavior I would like to achieve is once the user clicks out of the popup form (for example, he/she clicks another area in the application's main form) the popup form should disappear.
I have tried subscribing to the form's LostFocus event and creating the event handler for it. However, when I click away from the form, it simply goes behind the application form. Is LostFocus not the appropriate event? Or should I handle this in the popup form rather than from the "caller" form?
|
|
|
|
|
Have you tried putting form.Close() in the popup form's Deactivate() event?
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
No, I have not. I will do that though. Thanks.
|
|
|
|
|
Hi,
I'm trying to populate a listview control and my query is LINQ. I used one of the table (Production.Product) of AdventureWorks database.
At first i have problem populating the header, but i figured it out after an hour. The code below is the code on how to populate column in listview using LINQ.
Code:
----------------------------------------------------------------------------------------------
ProductID Name ProductNumber MakeFlag FinishedGoodsFlag Color
----------------------------------------------------------------------------------------------
317 LL Crankarm CA-5965 0 1 Black
318 ML Crankarm CA-5938 0 1 Black
319 HL Crankarm CA-5990 0 1 Black
320 Chainring CA-5932 0 1 Black
---------------------------------------------------------------------------------------------
DataClasses1DataContext db = new DataClasses1DataContext();
DataTable dt = new DataTable();
DataColumn dc = new DataColumn();
DataRow dr;
var products = from p in db.Products
where p.Color != null
select p;
#region getHeader
var headers = products.First();
foreach (var columnHeader in headers.GetType().GetProperties())
{
lvw.Columns.Add(columnHeader.Name);
}
#endregion
Now, my problem is how do i populate the result of my query and add it to listview. Actually, i can populate it like this,
ListViewItem lstItem = null;
foreach (var itms in products)
{
lstItem = new ListViewItem(itms.ProductID.ToString());
lstItem.SubItems.Add(itms.Name);
lstItem.SubItems.Add(itms.ProductNumber);
..... and so on
}
The problem on the above code is that, what if i have a 25 columns in my query result? I have to type in my code 25x the lstItem.SubItems.Add(value) which kinda hassle for me. I want my function in populating the listview to be dynamic.
Anyone out there can help me to solve my "simple (i think)" problem.
Thanks and regards
Jessie
if(you type your code here) {
Messagebox.Show("You help me a lot!");
}
else {
You help me = null;
}
|
|
|
|
|
ListView is quite limiting control. You can take a look on this extended ListView control A Much Easier to Use ListView[^] that supports data binding.
Hope it helps.
M.
|
|
|
|
|
Wow - that article has 453 5 votes, yet only 56 downloads.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
As soon as I saw you response I knew the article, it is an excellent article but a hugely complex control. I played with it but found it too complex for my requirements. Mind you I also trashed Infragistics for the same reason!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have no idea how the hamsters track the downloads but I guess that the low
number of downloads might be caused by the fact that the download is just a link to a sourceforge.net download?
All the best,
Dan
|
|
|
|
|
With the Browse Code tab it isn't really necessary to download the code to learn what it does and how it does it. That may explain the low numbers.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
thanks for the link. maybe ill try it later.
cheers!
if(you type your code here) {
Messagebox.Show("You help me a lot!");
}
else {
You help me = null;
}
|
|
|
|
|
Hello Everyone,
I'm trying to automate file's downloading process from my server using winscp command line stfp downloader. It was required to process some standard output to detect errors and some events, so I redirected the standard output and standard input of process and set the shellexcute to false. Now I'm able to see the output messages on rich text box using asycn readline (BeginOutputhttp://msdn.microsoft.com/en-us/library/system.diagnostics.process.beginoutputreadline.aspx[^]) method provided in Process library. Now my problem, how can I write my program such that it is able to write commands to standard input asycn and at same time making sure that no command is missed, if previous command is under processing.
Let say I've a text box and button..if I press a button then it writes the command on text box to standard input of the process and then it waits for the reply..and lets assume this whole task takes 2 seconds..but during this 2 seconds user can enter more commands which can not be ignored so must be added to some queue, which can executed later on. I'm not sure how should I achieve this? I'm sorry if I'm misunderstanding anything here..but I've no experience with mutli threading in C#..Please suggest some design pattern to do this..any help would be appreciated..
Thanks,
Regards
Shivam Kalra
modified on Friday, June 24, 2011 10:44 PM
|
|
|
|
|
You need to use a FIFO queue, lots of possible samples here[^].
The best things in life are not things.
|
|
|
|
|
Hello Experts,
I am Showing a form from another form. and it Set focus on Child Form by default.
But I don't want to lost focus from parent form.
So pls suggest me how can i do that?
For Ex: ChildForm Pf = new ChildForm;
Pf.Show();
Code set focus on PF Form but i do't want to change the previous focus.
Thanks
If you can think then I Can.
|
|
|
|
|
Try to do reset the focus on the caller form.
Form a = new Form();
a.Show();
this.Focus();
Bye
|
|
|
|
|
From MSDN[^]:
Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.
So, you should probably use Activate in this case.
|
|
|
|
|
That's a good point, I should be more detailed, but I was in hurry and he specifically spoke about the Focus.
Thanks
|
|
|
|
|
I transitioned from VB6 where SetFocus was the only thing you had (and an annoying thing too, kept throwing exceptions when it failed, rather than returning true or false).
I eventually discovered about the Select method while reading MSDN documentation about focus change events. Anyway, I'm guessing Select/Activate is more robust than SetFocus.
|
|
|
|
|
i'm using a msmq for my application and i create a queue when the application is loading.And to receive the message i set the timespan for 10, in the debug mode it works fine and the messages received as expected, but when i deploy the application in the release mode it gives a "timeout exception" at the receive method.
i would really appreciate your ideas about this .
thanks in advance.
|
|
|
|
|
If there are no messages in queue then it will raise tiemout exception.
No need to worry about that exception .. just catch it and say there are no messages in 'Q'.
No Defeat Is Final Until You Stop Trying!.......
|
|
|
|
|
You should also possibly increase your timeout (or at least make it configurable)
Or start another thread/method etc. to listen for the next message.
|
|
|
|