|
How to create region in C#
Assaf
|
|
|
|
|
Region myregion=new Region();
|
|
|
|
|
Region can be created easily
u can use the following code
#region "TestRegion"
Codes - Methods and functions
#end region
Gokul - MCSD:MCAD:MCP - Technical Lead - GFT INDIA
|
|
|
|
|
hi everyone I want to export data on my form that I got from a database to excel, I am working in C#. I have checked an example on code project but it doesnt help me. Thanks
|
|
|
|
|
|
thank you but isnt there an easier way? I dont want to work with xml files. thanks again
|
|
|
|
|
You can use excel object library to convert the generated file to excel native format
|
|
|
|
|
I dont know how to do that sorry Im still new with programming so I dont know alot can you maybe send me some code if its possible please. Thanks again
|
|
|
|
|
You can use that article to generate xml file and then convert it to xls using this piece of code:
<br />
private void savetoexcelformat(string currentpath, string pathtosave)<br />
{<br />
object missing = System.Reflection.Missing.Value;<br />
<br />
Excel.Application app = new Excel.Application();<br />
app.Visible = false;<br />
<br />
app.Workbooks.OpenXML(currentpath, missing,missing).SaveAs(pathtosave, Excel.XlFileFormat.xlWorkbookNormal, missing, missing,<br />
missing, missing, Excel.XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing, missing);<br />
app.Quit();<br />
<br />
}
|
|
|
|
|
Thanks for your help Ill try that. kind regards
|
|
|
|
|
The leave event occure when i push the tab button
What happen with me is when i put the first digit the leave event is called
this the code:
private void txtNewExpDate3_Leave(object sender, EventArgs e)
{
string val = this.txtNewExpDate3.Text;
if (this.txtNewExpDate3.TextLength.Equals(1))
this.txtNewExpDate3.Text = "0" + val;
}
and the MaxLength for the txtNewExpDate3 is 2
I do the same code is the same event in other textbox and it work properly.
Thanks in advance
Assaf
|
|
|
|
|
Hi Assaf
I tried to recreate the bug you stated...but on my machine the code given by u works just fine..i.e. only when u press "TAB" key, does the leave event fire and not in any other case..please retest your code.
thanks and regards
|
|
|
|
|
Hello sir/s, im pj.. how can i assign a shortcut key on a certain button, instead of putting an Ampersand ("&") besides the text of the button.. For exampe.. instead of pressing ALT + (the access key) for a button.. i would like only a single key.. like "ENTER" key to be associated with a certain button.. please Give me a sample code or any directions.. Thank you so much..
|
|
|
|
|
Trap the key you are interested in and invoke the event handler for the button or menu item
|
|
|
|
|
Sir, Thank you so much for replying on my message. Can you give me a sample code? I'm really having a hard time figuring out the event handlers, because i tried putting up some codes on the "KeyPress" event, but i only ended up having more errors. Thank you again sir.
|
|
|
|
|
What errors are you getting? You can check it like this:
<br />
private void Form1_KeyPress(object sender, KeyPressEventArgs e)<br />
{<br />
if (e.KeyChar == (char)Keys.A)<br />
{<br />
}<br />
<br />
if (e.KeyChar == (char)Keys.B)<br />
{<br />
}<br />
}<br />
|
|
|
|
|
Yes sir.. but i did it this way.. i was trying to designate the Keypress Event of a Button.. For example.. [Logout] Button..
if ( (e.KeyChar).ToString() == Keys.Escape)
{
if (MessageBox.Show("Do you wish to exit?", "Exit", MessageBoxButtons.YesNo) == DialogResult.No)
return;
this.Close();
}
But its not working..
|
|
|
|
|
1. If you want to quit your application when escape button is pressed then set form's cancelbutton property will help you.
2. You can test it like this:
<br />
if (e.KeyChar == (char)Keys.Escape)<br />
MessageBox.Show("escape was pressed");<br />
It works in the same way for Enter key too
|
|
|
|
|
Thank you so much sir.. I was trying to associate the "ENTER" and "/" key for the Event of a Button's Click.. But i could not make it work.. this is the error..
"Error 1 Operator '==' cannot be applied to operands of type 'char' and 'System.Windows.Forms.Keys' ".. I believe that the "Enter" Key is a windows forms key.. how can i CAST it to be something else..
|
|
|
|
|
Did you cast it to char as I showed in the example?
|
|
|
|
|
Thank you so much for that sir.. It works.. Sir, how can i can assign a hotkey to a Button?.. Ahm, for example.. I want a Button_Click event to be associated with a shortcut key.. Instead of me Pressing the Button itself, i just have to press a key from the keyboard.. like; Pressing the F2 key to be associated with
the Event of a Click of a Button.. Im really sorry for this sir.. I ask a lot of questions. I'm just new to C#, and I'm only a student.
|
|
|
|
|
if (e.KeyChar == (char)Keys.F2)
Button_Click(null,EventArgs.Empty)
|
|
|
|
|
Sir, i appreciate it so much.. Thank you very much for all the help that you have lend me.. Thank you so much sir..
|
|
|
|
|
You are welcome
|
|
|
|
|
Sir, thank you so much for all the help that you lend me.. .. until next time sir..
|
|
|
|