|
You must be setting the bool parameter somewhere, right? Won't this be solving your purpose?
private void button1_Click(object sender, EventArgs e) {
if (SomeBoolean) {
}
}
Here SomeBoolean is a class level variable.
The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures."
जय हिंद
|
|
|
|
|
It maybe can not be solved by this means. my purpose as below:
I want to override the button Click event,after override the click event it contains below code default,when I use the button_click,I have to pass a boolean value for it.
if (BlnFlag)
{
MessageBox.Show("");
}
else
{
return ; //do nothing
}
the BlnFlag is passed from WinForm which used this kind Button,it is not pass from the Button Class.
Could you give some suggestion?
|
|
|
|
|
Instead of asking about how you think that it should be solved I think that you should ask about what it is that you are trying to accomplish.
The event handler is normally called by an event. As you are trying to call it directly suggests that you are using the wrong tools for your solution.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
mctramp168 wrote: the BlnFlag is passed from WinForm which used this kind Button,it is not pass from the Button Class
Cant get this. The button must be on a winform. On the same winform, you will be setting the flag which will decide if the code should be executed or not.
I dont see any need to create your own button. You can use the code I had posted. If the boolean is set on some other form, and the button is on a different form, then there are a lot of ways to pass it on.
If you can post what exactly are you trying to do then maybe someone can help better.
The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures."
जय हिंद
|
|
|
|
|
thanks, I know the method you suggested, because many winform will use this kind of button, if I create my own button, then I can write my code code in this event, no need write the code under the others winform click event.so I have to pass a parameter from the current winform to this event decide to how to run it. can you give some comments on it?
|
|
|
|
|
Hi,
if you want to make a button do nothing, then disable it by setting its Enabled property false; that will alter its appearance so the user knows, and it will prevent some events from firing.
if you want a button to do alternate things, then I suggest you change its Text property so the user knows what to expect; your clicked handler can check the Text to see what needs to be done (beware internationization though).
if you don't want the appearance changed (I strongly object to invisible GUI changes mind you) you can use a flag somewhere and test it in the handler; one easy place to store such a flag would be in the Tag property: each Control has a Tag property (type is Object) that is available for any purpose you choose. I have never done that for disabling buttons, and I never will!
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:16 AM
|
|
|
|
|
You can do something like this and use the MyButton in place of the in built one wherever you need this functionality:
public class MyButton : Button
{
public new event EventHandler<ButtonClickEventArgs> Click;
public new void PerformClick()
{
PerformClick(false);
}
public void PerformClick(bool value)
{
OnClick(new ButtonClickEventArgs(value));
}
protected override void OnClick(EventArgs e)
{
OnClick(new ButtonClickEventArgs(false));
}
protected virtual void OnClick(ButtonClickEventArgs e)
{
EventHandler<ButtonClickEventArgs> eh = Click;
if (eh != null)
eh(this, e);
}
}
public class ButtonClickEventArgs : EventArgs
{
private bool m_Value;
public ButtonClickEventArgs(bool value)
{
m_Value = value;
}
public bool Value
{
get { return m_Value; }
}
}
Edited to get generic < > to display!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
modified on Wednesday, February 18, 2009 7:18 AM
|
|
|
|
|
Thank Dave , Do as you say ,the issues is solved.
|
|
|
|
|
How to create a .exe file for the project developed in dotnet with c#
|
|
|
|
|
When you compile the project, EXE will be produced automatically in bin directory.
|
|
|
|
|
To do it in a Good way, Add a Setup Project to your Application.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
I use a connection via a client machine, to SQL server which is on server. These two machines are in a workgroup. whenever I restart the client machine, I have to first, connect to my server through windows address bar, and then the connection via my code (C# 2005) can be established. If I restart my program any time after this, it can connect to SQL Server. But when I restart the client machine, this happens again. I use the appropriate network library. Would you please let me know why this happens and what should I do? (the logon to the client machine is done locally)
|
|
|
|
|
I use a Microsoft IIS in order to getting a service via client-server connection. but after some time passes, the service becomes down and I have to start it again. Would u please help me why and what should I do.
Thanks in advance!
|
|
|
|
|
Can you please be more Clear.
Are you talking about Windows Service ?
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
Dear All,
i have the datatable returns from sql store procedure:
sproResults = myUtils.ExecSproc(objSession, "spVoucherDetails_SelPending", printRunNumber);
and i loop through this table and try to write each row into a .csv file and save into disk, i know my current implementation wasn't quite right in here. Can someone plz advise me?
FileStream fStream = new FileStream(@"C:\Voucher\CompleteVoucher.csv", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
foreach (DataRow row in sproResults.Tables[0].Rows)
{
fStream.Write();
}
Thanks heaps.
|
|
|
|
|
AndieDu wrote: i know my current implementation wasn't quite right in here
Wrap the FileStream in using block. So it will get disposed when the scope ends. Something like
using(FileStream fStream = new FileStream(@"C:\Voucher\CompleteVoucher.csv", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
{
} If you are appending the text, easy way is to use File.AppendAllText[^]
|
|
|
|
|
do you by any chance get a blank file?
also i think you prob want to use WriteLine() method for each row
plus you need to write the values, something like this
foreach(DataRow row in sproResults.Tables[0].Rows)
{
object[] vals = row.ItemArray;
for(int i = 0; i < vals.Length - 1; i++)
{
fStream.Write((string)vals[i] + ",");
}
fStream.WriteLine((string)vals[vals.length - 1]);
}
then dont forget to close the stream i.e. fStream.Close();
EDIT: The above code would need ammending to handle null values, also FileStream will not support WriteLine. Thou i didnt actually specify the instance
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
Yummy, code that doesn't work.
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
well it certainly was not tested, but what would not work?
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
The individual objects in the ItemArray are strongly typed. string foo = (string)5; will not compile and in your code will throw a runtime exception instead. Also the case of null and csv escape characters really throws a wrench into things.
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
the string casting works fine with the ItemArray.
The null issue can be solved with a simple if statement.
The only issue with the code is FileStream does not support WriteLine(), i usually would use StreamWriter so was unaware of this issue.
and the CSV escape characters are just something that isnt going to change, personally i would use a tab delimters for more reliability but then thats a TSV, no?
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
The casting does not work with the ItemArray. The string casting only works if the ItemArray contains only strings which cannot be assumed, ever.
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
OK fair enough, i appreciate a cast from some object types will not work
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
Hi,
Can anyone please help me in .NET console application where i need to split a zip file into small zip file of size 1MB.
please provide examples or links .
Regards
S.Guhananth
|
|
|
|
|
1 - Read the zip file to a file stream
2 - Write to a new file until you reach 1MB.
3 - Create a new file and do step 2 again until you reach end of the zip file.
|
|
|
|