|
You could try finding the coordinates of the form and then see if the mouse is within range(this is what MouseEnter does.)
|
|
|
|
|
I haven't try that, but I want to do it through events.
Thanks very much ExpertComing. If you have some other idea it will be welcome, thanks a lot.
|
|
|
|
|
Make your own event that does the MouseEnter event's job.
|
|
|
|
|
Cuold you give me an example of that please?
Thanks a lot Expertoming !!
|
|
|
|
|
Cuold you give me an example of that please?.
Thanks a lot Expertoming !!
|
|
|
|
|
I posted a similar question a while back but wasnt able to find a solution. The issue I'm seeing is bizzare and yet there is no documentation of this in .Net.
Background: A control has "Visible" property and "VisibleChanged" event. This even is fired whenever the control is no longer "Visible".
Problem: I get the VisibleChanged event when I programmatically set a value for the "Visible" property. However, I do NOT get the "VisibleChnaged" event when the control becomes invisible when the tab page it is on is no longer the selected tab page. When the control is no longer "displayed" (e.g. not visible implicitely) the "Visible" property returns "false" but there is no event.
Stpes:
1) Create a form -- Form1 with a TabControl (tabControl1) and two tab pages (tabPage1, tabPage2).
2) On the tabPage1, add a control (button - b1) and add a b1_VisibleChanged handler. In the b1_VisibleChange method, write the following: "this.Text = b1.Visible.ToString(); " .
3) Add another button on Form1, b2 on the form which is for toggeling the visible property and add the following code for the b2_Click handler: "b1.Visible = !b1.Visible; "
4) Add another button on Form1, b3 on the form which displays the value of the Visible property of button b1. Add the following code in the b3_Click handler: "MessageBox.Show(b1.Visible.ToString()); "
Testing:
Make sure tabPage1 is selected and button b1 is being displayed.
Click on b3: it will show "true" message.
Click on b2: it will hide b1. The Form1 title will display "False".
Click on b3: it will show "false" message.
Click on b2 again: it will show b1. The Form1 title will display "True".
Now switch to tabPage2.
Click on b3: it will show "false" message. However, the Form1 title is still "true" implying that "b1_VisibleChanged" was never triggered.
Is there a way to assure a consistant behavior for VisibleChnaged?
Thanks for your help / suggestions.
- Malhar
|
|
|
|
|
I'm writing a service that copies specific MS Office documents(.doc, .xls,.mdb) after any event triggers a file system watcher (Change, Deleted, Renamed, Changed) and logs those file operations to a xml file. In order to copy those files to a hidden folder located in the user's My Documents Folder I was using in my windows form testing environment
Environment.GetFolderPath(Environment.SpecialFolder.Personal) and it worked perfectly and in order to determine the logged user I was using WindowsIdentity.GetCurrent().Name and when I tryied using them in the Windows Service code none of them worked as expected, Environment.GetFolderPath(Environment.SpecialFolder.Personal) returns nothing at all and WindowsIdentity.GetCurrent().Name returns the account name that the windows service is using.
Is there any way in which I can accomplish the recolection of this information using perhaps
another class or some other way of calling the class?
Thanks in advance, Mario
|
|
|
|
|
Hi all.
Please help me out with this.
What i am doing is that, in a small form i am displaying the current time. To keep it updated, i am using a timer and calling Invalidate on the form, after every 1000 ms, to paint the surface clean for me.
Now the problem is that, the time does not display at all. It sometimes appears, but for such a short duration that it is hardly visible.
Here's what i am doing:
class MyClock
{
.....
public MyClock()
{
m_timer = new System.Windows.Forms.Timer();
m_timer.Interval = 1000;
m_timer.Tick += new EventHandler(Start);
m_timer.Start();
}
private static void Start(Object o, EventArgs e)
{
m_timer.Stop();
m_form.Invalidate(true);
m_time = DateTime.Now;
string time = m_time.Hour + ":" + m_time.Minute + ":" + m_time.Second;
Brush b = Brushes.White;
m_gFormGraphic.DrawString(time, new Font("Verdana", 15), b, new PointF(20, 40));
m_timer.Start();
}
.....
}
I tried adding handlers for Validating and Validated, where i set a boolean variable and display the time only when the form has been validated. But this doesnt work too.
Any pointers will be highly appreciated.
Thanks in advance.
*** Who said nothing is impossible? I have been doing it for a long time ***
-- modified at 13:56 Wednesday 29th March, 2006
|
|
|
|
|
I would recommend moving the painting to your form's Paint handler, which will (eventually) be invoked as a result of calling Invalidate() or at any other time Windows deems it necessary to repaint the form.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Hey, thanks buddy...
I'll try that and let you know.
Thanks a lot.
*** Who said nothing is impossible? I have been doing it for a long time ***
|
|
|
|
|
CoolASL wrote: It sometimes appears, but for such a short duration that it is hardly visible.
That's because you are not doing the drawing in the Paint event. Now you are just drawing it on the screen, and when the form is being redrawn because you invalidated it, the time that you drew is painted over.
Why are you drawing the time as graphics anyway? Put the string in a label, and it will draw itself. When you change the Text property of the label, it will also invalidate itself so that it's redrawn.
---
b { font-weight: normal; }
|
|
|
|
|
Ok, please refresh me on this.
I call Invalidate; that repaints my form. Then i use DrawString to draw my string on the form.
Both are seperate entities... so whats the catch ????
Can you please brief me on what happening that i am not able to understand?
Thanks.
*** Who said nothing is impossible? I have been doing it for a long time ***
|
|
|
|
|
No, the Invalidate call doesn't repaint the form. It only flags that the form needs repainting. The actual repaint can't be done until the method call has returned, so the system can call the Paint event for all controls in the form.
---
b { font-weight: normal; }
|
|
|
|
|
Hello, may be some of you could help me. I have a winform with FormBorderStyle asigned to None (I need it in that way), and an AXWebBrowser with Dock asigned to Fill. My problem is that the MouseEnter event for the winform only work if I have a part of it visible, but in this case I must have the webbroser filling all the winform, so the event MouseEnter never work. And the webbrowser doen't have a MouseEnter event, so I can't call that event too. I need the event for enter and leaving.
I try:
((Control)this.browser).MouseEnter += new System.EventHandler(this.AlertWindow_MouseEnter);
But doesn't work !!!
Any ideas??
Thansk a lot.
|
|
|
|
|
I am relatively inexperienced in using delegates and asynchronous methods. I read several articles, and then I developed my own code with a mission to improve the performance. Wow! I cannot believe the difference in speed! However, the asynch operation fails sometimes, despite of the fact that it works most of the time. I am really at a loss how to fix this sporadic and erratic behavior.
This is a web application developed with Visual Studio 2003 (.NET framework 1.1). The following C# code snippet shows that I use two delegates to provide a built-in way to call two mainframe DB2 stored procedures, SPX and SPY. I need to execute SPX and SPY many times, each time passing different parameters as per signature of the method. This code is in the server-side Business Logic layer (behind an ASP.NET page to service a client request of a long running report).
With those asynch methods shown in the example, the code compiles and runs incredibly fast when compared to the old-fashioned way of making one call at a time. I was very happy with the performance and the results from the asynch executions were correct.
However, I came across a really peculiar and sporadic error from mscorlib.dll with an error message “object reference not set to an instance of an object”. This error is totally incomprehensible to me. Here are the symptoms: (1) It seems to me the error only occurred sporadically or randomly (because the application runs fine most of the time). (2) Whenever the error occurred, the call stack pointed to one of the many EndInvoke statements (not necessarily a particular EndInvoke statement, but randomly one of the many EndInvoke statements).
I apologize for putting down so much writing and code snippet. I sincerely hope someone can shed some light on this mysterious error. Any help or suggestion is greatly appreciated!
Code Snippet:
public delegate string SPXCaller(int Division);
public delegate string[] SPYCaller(int TimePeriod, int CategoryType, int Division);
public class AsyncMethods
{
public AsyncMethods()
{
}
public string ExecSPX(int Division)
{
//This method contains code to exec DB2 stored procedure SPX
//SPX returns 1 output parameter as string
}
public string[] ExecSPY(int TimePeriod, int CategoryType, int Division)
{
//This method contains code to exec DB2 stored procedure SPY
//SPY returns 5 output parameters as string[5]
}
}
public class BusinessData
{
public DataSet GetData()
{
//Declares a new DataSet to hold all data
DataSet dsData = new DataSet();
//Initiate the Asynchronous calls to exec SPX
AsyncMethods Task1 = new AsyncMethods();
SPXCaller Task1Caller = new SPXCaller(Task1.ExecSPX);
IAsyncResult Result1 = Task1Caller.BeginInvoke(8,null,null);
AsyncMethods Task2 = new AsyncMethods();
SPXCaller Task2Caller = new SPXCaller(Task2.ExecSPX);
IAsyncResult Result2 = Task2Caller.BeginInvoke(10,null,null);
//Initiate the Asynchronous calls to exec SPY
AsyncMethods Task11T = new AsyncMethods();
SPYCaller Task11TCaller = new SPYCaller(Task11T.ExecSPY);
IAsyncResult Result11T = Task11TCaller.BeginInvoke(1,1,8,null,null);
AsyncMethods Task12T = new AsyncMethods();
SPYCaller Task12TCaller = new SPYCaller(Task12T.ExecSPY);
IAsyncResult Result12T = Task12TCaller.BeginInvoke(1,2,8,null,null);
AsyncMethods Task11M = new AsyncMethods();
SPYCaller Task11MCaller = new SPYCaller(Task11M.ExecSPY);
IAsyncResult Result11M = Task11MCaller.BeginInvoke(1,1,10,null,null);
AsyncMethods Task12M = new AsyncMethods();
SPYCaller Task12MCaller = new SPYCaller(Task12M.ExecSPY);
IAsyncResult Result12M = Task12MCaller.BeginInvoke(1,2,10,null,null);
AsyncMethods Task21T = new AsyncMethods();
SPYCaller Task21TCaller = new SPYCaller(Task21T.ExecSPY);
IAsyncResult Result21T = Task21TCaller.BeginInvoke(2,1,8,null,null);
AsyncMethods Task22T = new AsyncMethods();
SPYCaller Task22TCaller = new SPYCaller(Task22T.ExecSPY);
IAsyncResult Result22T = Task22TCaller.BeginInvoke(2,2,8,null,null);
AsyncMethods Task23T = new AsyncMethods();
SPYCaller Task23TCaller = new SPYCaller(Task23T.ExecSPY);
IAsyncResult Result23T = Task23TCaller.BeginInvoke(2,3,8,null,null);
AsyncMethods Task21M = new AsyncMethods();
SPYCaller Task21MCaller = new SPYCaller(Task21M.ExecSPY);
IAsyncResult Result21M = Task21MCaller.BeginInvoke(2,1,10,null,null);
AsyncMethods Task22M = new AsyncMethods();
SPYCaller Task22MCaller = new SPYCaller(Task22M.ExecSPY);
IAsyncResult Result22M = Task22MCaller.BeginInvoke(2,2,10,null,null);
AsyncMethods Task23M = new AsyncMethods();
SPYCaller Task23MCaller = new SPYCaller(Task23M.ExecSPY);
IAsyncResult Result23M = Task23MCaller.BeginInvoke(2,3,10,null,null);
//All calls to BeginInvoke return right away.
//We can immediately move on to do another task.
//The following independent, long running task retrieves PO data
//while waiting for all asynch executions (DB2 store proc) to finish.
DataTable dtPOData = GetPOData();
//Now, retrieve the return values by calling the EndInvoke method.
//Retrieve results from SPXCaller
string Ret1 = Task1Caller.EndInvoke(Result1);
string Ret2 = Task2Caller.EndInvoke(Result2);
//Retrieve results from SPYCaller
string[] Ret11T = Task11TCaller.EndInvoke(Result11T);
string[] Ret12T = Task12TCaller.EndInvoke(Result12T);
string[] Ret11M = Task11MCaller.EndInvoke(Result11M);
string[] Ret12M = Task12MCaller.EndInvoke(Result12M);
string[] Ret21T = Task21TCaller.EndInvoke(Result21T);
string[] Ret22T = Task22TCaller.EndInvoke(Result22T);
string[] Ret23T = Task23TCaller.EndInvoke(Result23T);
string[] Ret21M = Task21MCaller.EndInvoke(Result21M);
string[] Ret22M = Task22MCaller.EndInvoke(Result22M);
string[] Ret23M = Task23MCaller.EndInvoke(Result23M);
//Some source code omitted here. The code packs all results
//into a dataset dsData with multiple datatables.
return dsData;
}
}
swanmynova
|
|
|
|
|
Well, upon initial glance it all seems ok...what line of code is it crashing on? You should first find out where the null reference exception is occurring; what's most likely occurring is that some object is being accessed by multiple threads. One of the threads sets the object to null, then another thread tries to use that object after the fact, causing the error. But it's difficult to debug it unless you know where the error is occurring.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Hi Judah,
Thank you very much for your reply. As I mentioned in my original message, the line of code that caused the reference exception is one of the many EndInvoke statements (not always the same one, but one of them randomly). Like I said before, the application works most of the time. So, this leads me to think that there is no programming error. But sporadically it crashed on one of the EndInvoke statements as indicated by the Exception Management. So this bug is really incomprehensible to me.
Thanks again,
SL
|
|
|
|
|
When you're executing asynchronous code, EndInvoke will re-throw any unhandled errors that occurred somewhere in your asynchronous code blocks (the code that gets executed on background threads). This is by design.
What I would do is put some try/catch around the code that gets executed on a background thread. Log it somehow by outputting to the console, a file, anything that lets you track it down when it happens. Then when it happens, make sure you log the stack trace, the error message, and any other error information that will help you solve it. Also, in your asynchronous code, validate all the data you're dealing with. If you're using an object that is shared among the other threads, make no assumptions about it! Check if such resources are null or in an invalid state before using them.
|
|
|
|
|
Thank you, I will dig in further.
|
|
|
|
|
Has anyone seen a program that will tell you the FLOPS of a processor in C#?
|
|
|
|
|
I'm having a slight problem with flags. I downloaded a small class from CP called Task Scheduler. It contains an enum called DaysOfTheWeek. This enumeration contains all the seven days of the week. This enumeration has the Flag option set to on and as i read somewhere, multiple flags can be passed at once by using the pipe operator (|). Now the class contains a function which takes the enumeration DaysOfTheWeek as a parameter. When I have to call the function, I can easily do so by writing
TestFunction(DaysOfTheWeek.Monday)
That was easy. Now, I have seven check boxes on my form called chkSunday, chkMonday....chkSaturday. Now, I have to call the function by passing the flags which in turn depend on the check boxes that are selected. For example, if the user has selected chkMonday and chkSunday, I would call the function like this
TestFunction(DaysOfTheWeek.Monday | DaysOfTheWeek.Sunday)
This is where the the problem lies. i can't possibly write a set of if else statements that take into account all the possible combinations of checkboxes being selected and appropriately calling the function. How do I do this?
I thought of this but it doesnt work:
<br />
TaskScheduler.DaysOfTheWeek enmDays;<br />
if (chkSunday.Checked == true)<br />
enmDays = enmDays | DaysOfTheWeek.Sunday;<br />
if (chkMonday.Checked == true)<br />
enmDays = enmDays | DaysOfTheWeek.Monday;<br />
if (chkTuesday.Checked == true)<br />
enmDays = enmDays | DaysOfTheWeek.Tuesday;<br />
if (chkWednesday.Checked == true)<br />
enmDays = enmDays | DaysOfTheWeek.Wednesday;<br />
if (chkThursday.Checked == true)<br />
enmDays = enmDays | DaysOfTheWeek.Thursday;<br />
if (chkFriday.Checked == true)<br />
enmDays = enmDays | DaysOfTheWeek.Friday;<br />
if (chkSaturday.Checked == true)<br />
enmDays = enmDays | DaysOfTheWeek.Saturday;<br />
TestFunction(enmDays);<br />
|
|
|
|
|
Standard question #1:
What do you mean by "not working"?
Mridang Agarwal wrote: i can't possibly write a set of if else statements that take into account all the possible combinations of checkboxes being selected and appropriately calling the function.
Yes, you can. It's only 128 combinations. I can very well understand if you don't want to do it, but it's clearly possible to do.
---
b { font-weight: normal; }
|
|
|
|
|
Why not just use a loop?
ArrayList checkBoxes = new ArrayList();
chkSunday.Tag = DaysOfTheWeek.Sunday;
checkBoxes.Add (chkSunday);
...
chkSunday.Tag = DaysOfTheWeek.Saturday;
checkBoxes.Add (chkSaturday);
DaysOfTheWeek selectedDays = DaysOfTheWeek.None;
for (int nDay=0; (nDay < checkBoxes.Count); nDay++) {
CheckBox cb = checkBoxes[nDay] as CheckBox;
if (cb.Checked) {
if (selectedDays == DaysOfTheWeek.None)
selectedDays = (DaysOfTheWeek) cb.Tag;
else
selectedDays |= (DaysOfTheWeek) cb.Tag;
}
} /ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
There isn't a DaysOfTheWeek.None . What do I do now?
|
|
|
|
|
Make up your own enum (eg: MyDayOfTheWeek ) or use a set of days of the week, where the empty set implies "no day selected".
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|