|
This is driving me nuts, can some help? I am new to c# but an old hand at C++ and Java.
It is probably very basic but here goes.
http://msdn2.microsoft.com/en-us/system.windows.forms.notifyicon.balloontipclicked.aspx[^]
This is how to use this event but it is not working.
so I add the event handler to the object
this.WSNotifyIcon.BalloonTipClicked += new System.EventHandler(this.WSNotifyIcon_BalloonTipClicked);
(WSNotifyIcon is an instance of NotifyIcon
then I define my event function
public void WSNotifyIcon_BalloonTipClicked(Object sender, uint id)
{
Console.WriteLine("clicked event.");
}
The method is already part of the NotifyIcon class so I should not have to do anything else right?
Thanks
|
|
|
|
|
I believe that will be all you have to do to get it to work. Did you test it?
|
|
|
|
|
You're basically saying, "when the balloon tip is clicked, call the WSNotifyIcon_BalloonTipClicked function. It's of type EventHandler."
The problem lies in the fact that your WSNotifyIcon_BalloonTipClicked doesn't match the EventHandler signature. If you look at the signature of EventHandler delegate, it returns void (you're good there), it takes an object as its first parameter (you're good there) and it takes an EventArgs as its second parameter (oops! yours takes a uint).
Make your WSNotifyIcon_BalloonTipClicked conform to the EventHandler signature. To do that, change the second parameter to be type EventArgs.
p.s. in C# 2, you can omit the "new System.EventHandler(" part. For example, this is valid and more concise syntax:
this.WSNotifyIcon.BalloonTipClicked += this.WSNotifyIcon_BalloonTipClicked;
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Goof around music jam with my brothers (with video)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I love all the random formatting that is provided, but I'm having an issue with the default percent formatting. I databind a decimal value in a dataset to a textbox, and set the default formatting to "#,##0.##%" The problem is my end-user is slightly annoyed with the resulting format.
If the end user inputs 2.34 (with their interpretation of 2.34%), it formats itself to "234%". If the end-user wants to end up with a display of "2.34%", he needs to entier either that, or .0234.
My question is simply this, is there a way to override the percent formatting, or another custom string taht I can use that won't automatically do the "multiply by 100" in the format?
|
|
|
|
|
I can think of another way to do it, but it's a bit longer:
1- Create the text box.
2- Parse it into a float to validate the input
3- Format the float with your desired format into a string
4- Do whatever you want with that string
The code I used is like this:
float test = float.Parse(textBox1.Text);
MessageBox.Show(test.ToString("#,###.##") + "%");
|
|
|
|
|
Use apostrophes in the format string to specify literal text:
"#,##0.##'%'"
---
b { font-weight: normal; }
|
|
|
|
|
|
I don't know if it's a bug or not but i have a listbox with some items in there. on the click event of the listbox i put a while loop. what happens is that the listbox automatically highlite the last item. You can test that on ur VS2005. Is there a way to fix that?
Donkaiser
|
|
|
|
|
Hello donkaiser.
You might want to post the code of the vent handler, so that perhaps we could understand the problem more.
|
|
|
|
|
sorry i should have done that. i guess im not very descriptive.
private void listBox2_Click(object sender, EventArgs e)
{
bool inf = true;
do{
Application.DoEvents();
Debug.WriteLine("looping");
}while(inf);
}
and add some items to your listbox. You will see that it keeps selecting the last item automatically no matter what you do.
Donkaiser
|
|
|
|
|
Hello
First:
You must have noticed that your loop goes forever. Are you sure you want that?
Second:
Your problem is because your listbox captures the mouse each time your loop goes. Try this code:
private void listBox2_Click(object sender, EventArgs e)
{
bool inf = true;
do{
listBox2.Capture = false; //To release the mouse
Application.DoEvents();
Debug.WriteLine("looping");
}while(inf);
}
But again this loop will go forever. If that is your exact code, I hope you reconsider it.
|
|
|
|
|
I want to create a hatch brush using as hatch style a string ... for example "BackwardDiagonal"
how can I do something like :
HatchBrush hb = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Red);
using only the string "BackwardDiagonal" ?
modified 30-Nov-21 21:01pm.
|
|
|
|
|
Well, you could either use Reflection (I haven't done this myself), or you would need to parse your string in the constructor:
public HatchBrush(string type, Color color)
{
switch(type)
{
case "BackwardDiagonal":
return new BackwardDiagonalBrush(...);
default:
return new SomeDefaultBrush(...);
}
}
However, this isn't as flexible as the Relfection approach
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
with switch and case it would take some time because I want to have multiple choices (over 10 or 20)
I'll consider finding more about Relfection .
Thanks a lot.
modified 30-Nov-21 21:01pm.
|
|
|
|
|
You can use Enum.Parse to do this
HatchBrush b = new HatchBrush((HatchStyle)Enum.Parse(typeof(HatchStyle),"BackgroundDiagonal"),Color.Gray,Color.LightGray);
|
|
|
|
|
Problem solved
Thanks a lot.
modified 30-Nov-21 21:01pm.
|
|
|
|
|
Why do I get an error saying "Input string was not in correct format" when I do the following?
sb.AppendLine(string.Format("\t\t\tpublic static string {0}TableName { get { return \"{0}\"; } }", tr.TABLE_NAME));
sb is a stringbuilder
tr.TABLE_NAME is a string
I'm thinking that it is probably something to do with the curly braces in there, almost like it expects a date format string or something in there.
I know the code is ugly, but it's just for a little quick utility.
|
|
|
|
|
Apparently, you have to escape a single "{" with another "{". You also have to do this with the closing braces.
|
|
|
|
|
Well, it's definitely the curly braces. That's confusing the Format method. When you want to put a '{' in the string use '{{'.
Logifusion[^]
|
|
|
|
|
Hi.
I'm new to C# but want to learn.
Can someone tell me how to implement (where to enter code mentioned below) a single process instance object that I found on:
http://www.codeproject.com/csharp/cssingprocess.asp?&forumid=11773
I can make that work, but then I don't see title bar of my program, so I'm sure I'm missed up somewhere
Thanks in advance.
|
|
|
|
|
I'm not sure where your problem is. Create a new windows application project in visual studio. Download the code that goes with the article you have. It's a CS file. Add that to your project. Make sure the namespaces are the same. Look in the Form1 code and find the Main method and add the following (as detailed in the article):
using(SingleProgramInstance spi = new SingleProgramInstance())
{
if (spi.IsSingleInstance)
{
Application.Run(new Form1());
}
else
{
spi.RaiseOtherProcess();
}
}
Logifusion[^]
|
|
|
|
|
I want to check the input to a text box is numeric (e.g., mmddyyyy). Is there a command for this?
sas
|
|
|
|
|
If you're using framework 2.0 you could use DateTime.TryParse or the MaskedTextBox . Otherwise use DateTime.Parse .
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
Int.TryParse
Will return true if the string is a number
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hello again all. I found an example of a fully editable datagrid that was attached to the Northwind database. I have been tinkering with it to use with my own data. The code uses the Microsoft SQL Helper.cs class.
Originally the code opened the page, and returned all the employees in the NW database. I ran the project and everything was fine.
Original code:
private void BindData()<br />
{<br />
ds = new DataSet();<br />
Session["ds"]=ds;<br />
dt = ds.Tables[0];<br />
Session["dt"]=dt;<br />
DataGrid1.DataSource=dt;<br />
DataGrid1.DataBind();<br />
<br />
}
I changed it to take a parameter. The user enters a part number in a text box, and clicks a search button and then I want the datagrid to populate. It returns 3 blank rows. When I went through the debugger it looks like it tries to run through the SQLHelper code before it looks at the button click function.
I think it has to do with how I'm sending the parameters but I'm not sure because if I change the stored procedure and code for no parameters, it works.
Current code:
private void BindData()<br />
{<br />
strPartNumberInputReference = txtSearchPart.Text;<br />
ds = new DataSet();<br />
SqlParameter param = new SqlParameter("@PartID", strPartNumberInputReference);<br />
ds=SqlHelper.ExecuteDataset(this.connectionString, CommandType.StoredProcedure, "dbo.GetPartInfoTest", param);<br />
Session["ds"]=ds;<br />
dt = ds.Tables[0];<br />
Session["dt"]=dt;<br />
dgParts.DataSource=dt;<br />
dgParts.DataBind();<br />
txtSearchPart.Text = "";<br />
<br />
}
Does anyone have any ideas? I didn't post the SQLHelper code as it is LONG but if someone is willing to help and needs it let me know.
Thanks again to all who help!
|
|
|
|