|
Ah, I figured it out. Your supposed to use beginReceive() Perhaps what I was using was for transactional code or something.
Cheers,
Jim
|
|
|
|
|
Having a bit of a tricky problem with the contention for the assignment of the value to a variable. I would like the variable to be assigned in two ways both in the onLoad event. If the user clicks on a menu item, then it becomes checked and assigns the value based upon which of the appropriate menu items is selected. However, if the user does not select a menu item, the value is assigned based upon the application settings (as stored in an XSD/XML initialization file) when the application is opened. The question is this - how do I differentiate between whether the user has selected a MenuItem from the menu or if the user has only opened the application anew without making such a selection?
If the menu item is selected, assign the variable based upon the menu item (the assignment variable currently works), and if the user does not make such a selection, then use the XSD/XML file to assign the variable.
Example:
<br />
private void onLoad(object sender, System.EventArgs e)<br />
{<br />
if ((mnuItem1.clicked) || (mnuItem2.clicked) ||<br />
(mnunItem3.clicked) || (mnuItem4.clicked))<br />
{<br />
strVariable = [value from menu item]<br />
}<br />
else<br />
{<br />
strVariable = [value from XSD/XML initialization file]<br />
}<br />
}<br />
Alternatively:
<br />
private void onLoad(object sender, System.EventArgs e)<br />
{<br />
if ((MenuItem)sender).Name == "mnuItem1") || <br />
(MenuItem)sender).Name == "mnuItem2") ||<br />
(MenuItem)sender).Name == "mnuItem3") ||<br />
(MenuItem)sender).Name == "mnuItem4"))<br />
{<br />
strVariable = [value from menu item]<br />
}<br />
else<br />
{<br />
strVariable = [value from XSD/XML initialization file]<br />
}<br />
}<br />
Neither of the above code segments works because there is neither a .clicked nor a .name property for the MenuItem class. The code should be processed based upon whether the user selects the menu item or if the user does nothing and just allows their application settings to reload into the variable. How do I check to see whether the user made the selection from the menu, or is merely opening the application? Would really appreciate the assistance!
|
|
|
|
|
Instead of this:
new_phoenix wrote:
if ((MenuItem)sender).Name == "mnuItem1") ||
(MenuItem)sender).Name == "mnuItem2") ||
(MenuItem)sender).Name == "mnuItem3") ||
(MenuItem)sender).Name == "mnuItem4"))
{
Try this:
if ((MenuItem)sender) == mnuItem1) ||
(MenuItem)sender) == mnuItem2) ||
(MenuItem)sender) == mnuItem3) ||
(MenuItem)sender) == mnuItem4))
There's no need to compare a property: you can always compare the reference and see if they are the same object.
Yes, even I am blogging now!
|
|
|
|
|
Daniel Turini:
I just had a Homer Simpson moment when I realized that a menu selection does not return a value to the onLoad event. Thus, I developed a potential workaround solution. Tell me if you think that this is a viable alternative. I have coded it, but I have not yet tested it.
If I were to put a protected string variable in the variables section of the form and assign it to String.Empty, and then I assigned that string variable in each of the menu selection items, and then in the onLoad event checked to see if that variable was empty or not. Presume that the menu selection reloads the onLoad event. If not empty, then it must have been a menu selection, so the variable could be processed that way. If the variable is empty, then the user must have just started to run the program because the variable was assigned during initialization to String.Empty. Tell me, do you think that this approach would work?
As usual, I appreciate all input and detailed explanations about alternative courses of action. All insights are valuable and appreciated !!!
Thanks, Daniel Turini
|
|
|
|
|
Hi,
I recently downloaded the code from a project on this site called TaskbarNotification. It is a little msn style popup window that pops up on the taskbar. When using this class in a single threaded application it works fine. Now i have to use multi-threading because the program checks a mysql database for updates and pop's up the window when there is one. Since i need to loop indefinatly I had to thread the task. Now a line only appears at the bottom of the taskbar and goes away. If I add a call to MessageBox.Show("whatever") write after i call taskbarNotification1.show() the message box pops up and the taskbar notification window shows. I thought the problem could be the passing of the background bitmap to the taskbarNofication class. I tried to initialize the background bitmap in the actual class but get a resource error. I guess threads don't have access to the resources the Microsoft Studio makes you add. Any help would be appreciated..
Thanks..
Mark
|
|
|
|
|
Hi All,
This ones a stumper.... Some more detail..
The thread gets started that loops indefinately. It checks a database for a new message and displays it in the taskbar popup window. In the thread class i created there is a block of code initializing the popup window. When you call the show function:
taskbarNotifier1.Show("Chatter",what,500,5000,200);
You get a small line on top of the taskbar. If I change the code to this..
taskbarNotifier1.Show("Chatter",what,500,5000,200);
MessageBox.Show(what);
The popup window shows as long as the messagebox is open. When I close the messagebox the popup disapears.
This is very strange almost bug like.
Does anyone have any suggestions or thoughts on this.. Please help!!!
Thanks,
Mark
|
|
|
|
|
I am experimenting with "XmlValidatingReader" and want to create a event handler which gets called there occurs some validation error(schema mismatch etc..) But could not find where this class is located??
I am using .NET framework 2.0, VS 2005 beta1..
Is there any other way to validate xml with schema?
REgards.
MaulikCE
|
|
|
|
|
|
Why is it, that when I create a new AppDomain and attempt to load an assembly into it, I get "ResolveEventArgs is not marked as Serializable"?
I mean, duh, it's not marked Serializable. How do I work around this problem?
It seems that the .NET implementation prevents you from using the AssemblyResolve event in a new AppDomain. Is this true? Is there a better way that would actually work?
Thanks!
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
Marc Clifton wrote:
It seems that the .NET implementation prevents you from using the AssemblyResolve event in a new AppDomain. Is this true? Is there a better way that would actually work?
The .NET framework is trying to serialize a ResolveEventArgs because it's trying to make a call that crosses domains. Are you capturing the AssemblyResolve event on the newly created AppDomain? If so, you should do so from the loaded assembly only, so the call does not cross domains.
I'm not sure that this explanation was clear enough...
Yes, even I am blogging now!
|
|
|
|
|
|
does anyone know how to automate the scrolling down to the bottom of rich text box and the scroll bar everytime a new string has been appended?
|
|
|
|
|
class RichTextBox : System.Windows.Forms.RichTextBox
{
void ScrollToEnd()
{
Point pt2 = GetPositionFromCharIndex(0);
Point pt = GetPositionFromCharIndex(TextLength);
const int msg = 0x400 + 222;
Point point = new Point(0, Font.Height + pt.Y - pt2.Y - Height);
SendMessage(Handle, msg, 0, ref point);
}
[DllImport("user32.dll")]
extern static int SendMessage(IntPtr hwnd, int id, int res, ref Point pos);
protected override void OnSizeChanged(EventArgs e)
{
ScrollToEnd();
base.OnSizeChanged (e);
}
protected override void OnTextChanged(EventArgs e)
{
ScrollToEnd();
base.OnTextChanged (e);
}
}
top secret Download xacc-ide 0.0.3 now! See some screenshots
|
|
|
|
|
|
It should be possible without P/Invoke as well:
After appending a string call this:
richTextBox1.Select(richTextBox1.Text.Length, 0);
richTextBox1.ScrollToCaret(); Regards,
mav
|
|
|
|
|
is there any other way? it doesnot seem to work. the rich text box still does not automatically scroll down. as well as the scroll bar thanks
|
|
|
|
|
You're right, it _should_ work (as I wrote), but unfortunately doesn't.
There's a bug in the .NET RichTextBox that prevents ScrollToCaret() from working when the RichTextBox doesn't have Focus.
If you add the line
richTextBox1.Focus(); before the call to ScrollToCaret() it'll work (I've tried it this time ).
mav
|
|
|
|
|
It's not a bug. It's documented in the TextBoxBase class that TextBox and RichTextBox inherit from. In order for ScrollToCaret to work, the control must have the focus.
Remarks<br />
This method enables you to scroll the contents of the control until the caret is within the visibile region of the control. If the caret is positioned below the visible region of the control, the ScrollToCaret method will scroll the contents of the control until the caret is visible at the bottom of the control. If the caret is positioned above the visible region of the control, this method scrolls the contents of the control until the caret is visible at the top of the control. You can use this method in a multiline text box to ensure that the current text entry point is within the visible region of the control.<br />
<br />
Note This method has no effect if the control does not have focus or if the caret is already positioned in the visible region of the control.<br />
Docs on TextBoxBase.ScrollToCaret Method[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
thank you for the help. , it works now.
|
|
|
|
|
IIRC, calling AppendText() seemed to do that automatically.
Regards
Senthil
|
|
|
|
|
Regardless of whether AppendText() really scrolls to the end (I don't know if it does), everybody should be careful when using this function!
There's another bug (introduced in .NET 1.1 IIRC) that limits text in a TextBox to 32K, no matter what the MaxLength property is set to, when text is appended via AppendText() !
Using textBox1.Text += "NewText"; instead works as expected.
You can try it:
TextBox tb = new TextBox();
tb.MaxLength = 0;
tb.Text = new string('0', 32767);
tb.AppendText("12345");
System.Diagnostics.Trace.Assert(tb.Text.Length == 32767+5); This will throw an assertion every time.
I came across this bug when I had written a program to concatenate many texts and didn't notice at first, until my colleague told me that ~500KB of text concatenated only gave a 32KB file, although I had explicitely set MaxLength to 0.
mav
|
|
|
|
|
thank you, it already works with scrolltocaret() and focus()
|
|
|
|
|
The code I posted above does exactly what you are looking for, its clean and simple, I dont understand why ppl wanna mess different fucntionality. Also my version does not need focusing, and it works with wordwarp, and it handles resizing of the control.
top secret Download xacc-ide 0.0.3 now! See some screenshots
|
|
|
|
|
i'm bad enough at trigonometry without having to code it
cosine rule is: b2=a2+c2- 2bccosA
so: cosB=a2+c2-b2/2ac
B=cos^-1(cosB)
I'm having problems coding the last line,'cos^-1',any help appreciated
|
|
|
|
|