|
Can Some help me to make a textbox in which user can type only numerical or Uppercase charecters ?
|
|
|
|
|
|
Itis bretty easy just override the OnTextChanged event and check the new char if it is a number or uppercase,you can know about numbers by putting them in an array,or just trying double.TryParse() function,in a try-catch block;
|
|
|
|
|
Capture the KeyPress Event of TextBox
The following is for numeric. Add condition for Upper Case.
private void TextBoxInceptionANAKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
try
{
//Handle only if the value being entered is NUMERIC
if (e.KeyChar >= (char) 48 && e.KeyChar <= (char) 57 )
{
e.Handled = false;
}
else
{
//Sound beep
MutualFundHelper.SoundBeep();
e.Handled = true;
}
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
|
|
|
|
|
Hello,
I have dynamically allocated menu items, and for eahc of these menus I have submenus.
foreach (object i in versionsAnddates) {
string[] splitStr = Convert.ToString(i).Split('~');
SubMenu = new MenuItem ();
SubMenu.Text = "Version: "+splitStr[0]+" --- "+splitStr[1];
this.projectsMenu.MenuItems.AddRange (new MenuItem[] {this.SubMenu});
this.projectsSubMenu.Click += new System.EventHandler(this.Version_Click);
}
How can I pass some of the parameters (some string for example) to the Version_Click event when menu item is clicked?
Thank you
|
|
|
|
|
In those situations I prefer inheriting my own class from MenuItem e.g.:
private class MyMenuItem : MenuItem
{
private string _version;
public MyMenuItem(string version) : base()
{
_version = version;
string[] splitStr = Convert.ToString(_version).Split('~');
base.Text = "Version: "+splitStr[0]+" --- "+splitStr[1];
}
public string Version
{
get { return _version; }
}
}
Your code would then look like:
foreach (object i in versionsAnddates) {
SubMenu = new MyMenuItem (Convert.ToString(i));
this.projectsMenu.MenuItems.AddRange (new MenuItem[] {this.SubMenu});
this.projectsSubMenu.Click += new System.EventHandler(this.Version_Click);
}
and the event handler...
private void Version_Click(object sender, EventArgs e)
{
MyMenuItem mmi = sender as MyMenuItem;
if (mmi != null)
{
Console.WriteLine(mmi.Version);
}
}
|
|
|
|
|
Thank you so much,
It was a perfect solution.
Thank you again
|
|
|
|
|
Hi everyone,
It is said that using Xml Document to store application settings is better than store settings in an Ini file or Windows Registry, so I'd like to try this new way of storing settings. But I don't know how to Read/Write settings form/to an Xml Doucment. Who can give me a sample code(s) or E-mail these codes to me?
For example, in an Ini file:
[UserInfo]
FirstName=Cheng
LastName=Zhong
Age=19
[Window]
X=120
Y=345
Width=320
Height=240
Font.FamilyName=Arial
Font.Size=8
Font.Bold=True
Font.CharSet=936
How can I write the settings above to an Xml file(not convert it to Xml)?
And how can I load the settings like "Age" from an Xml file?
And how can I get the list of "Sections" or "Keywords"(maybe it is called
"Attributes" or "Nodes" in Xml)?
Both VB.Net Codes or C# Codes are OK. Thank you!
More, do you have some advice to store none-string-type settings and none-integer-type settings, like Color(System.Drawing.Color), Font (System.Drawing.Font), Handle(System.IntPtr), Array(System.Array)?
E-mail: zc_djx@hotmail.com
I'm learning VB.Net & C#, you are always welcome to help me!
|
|
|
|
|
Zhong Cheng wrote:
Who can give me a sample code(s) or E-mail these codes to me?
noway. There is lot of samples on the web...
Zhong Cheng wrote:
How can I write the settings above to an Xml file(not convert it to Xml)?
It's called XML file because it contains data in XML. Why would you want not to convert it into XML??
Please read about .NET Configuration files[^]. This is what is in 99% meant as configuration in XML, standardized API and format, most of work is already done in .NET framework - most of answers to your questions are there. For the rest, you can ask here again.
Zhong Cheng wrote:
I'm learning VB.Net & C#, you are always welcome to help me!
Start with a good book or/and http://msdn.microsoft.com/[^]
David
|
|
|
|
|
dnh wrote:
It's called XML file because it contains data in XML. Why would you want not to convert it into XML??
It is not difficult to rewrite data/settings in Ini file to an XML file.
E-mail: zc_djx@hotmail.com
I'm learning VB.Net & C#, you are always welcome to help me!
|
|
|
|
|
In addition to what dnh said, look at the System.Xml.Serialization.XmlSerializer object. It can convert an entire class to and from and XML file.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
Hi
i work with System.Drawing.Graphic class . i want to save the variable to an image object and then restore the image to variable of graphic class .
and another question :
how can get the color of pixel in form ? have i must use the graphic class ?
2-when i draw a line in form and minimize the form after resoring form line is cleared . what i must do to save the contant of form ?
Regards Amir Jalaly
|
|
|
|
|
Amir Jalaly wrote:
i want to save the variable to an image object and then restore the image to variable of graphic class
WHAT?? This makes no sense what-so-ever. The Graphics class doesn't represent an image of anything. Perhaps a better explanation of what you want to accomplish would help.
Amir Jalaly wrote:
when i draw a line in form and minimize the form after resoring form line is cleared .
All your drawing on the form surface must be done in the Form's OnPaint event. You have to repaint your graphic items every time the form is redrawn, which happens quite frequently.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi dear me too is working on these images and graphics
ans: Q2:- Register the event handler of OnPaint
to save the color of pixel use Getpixel(), it returns a Color object u can use it later.
Graphics class surely helps.
Abt Q1 i can't understand what have u asked plz ellaborate it
|
|
|
|
|
HI
Thanks for your answer .
i don't understand how i must use GetPixel . is that a func of graphic class ?
Can you help me more ?
Also i want to fill a area that i draw in my form . can help me plz ?
Regards Amir Jalaly
|
|
|
|
|
Hi,
How could I start a c# application and communicate
with another application in another process ?
e.g. my application want to communicate with an
already-opened MS Word document.
Thanks
|
|
|
|
|
|
Hey,
Has anyone updated windows components via a setup.exe??
Here is what I'm trying to do in a setup.exe.. I need to make sure the version of .NET is 1.1 if not, update it, check to see if the directx is version 9.0c...if it's not update it...then install the original package (which requires .NET1.1 and directx 9.0c.
This way I don't have to have the user manually update the windows components in order to run the program I'm installing..
Any advice would be great!
Thanks,
|
|
|
|
|
Just wondering, whats the deployment medium and also the programs to be updated will they be included (redistributables) ?
~Alexander Kent
|
|
|
|
|
Printed to CDs will be the primary deployment medium (maybe downloadable as well)
yes, .NET and the directx will be included (they both are redistributable.)
|
|
|
|
|
I feel I need to share this pain. I have been struggling for days now to get something simple to work for me. That is to print out a Word document(rtf format) to a printer using Word. It also has to work with multiple versions of Word (so far 2000 and 2003). I thought I would share everything that I have learnt.
If you want this to work for multiple versions, install the earliest version of Word and Add Reference to it's COM component and develop against these.
Next to the code...
<br />
Word.ApplicationClass ac = new Word.ApplicationClass();<br />
Word.Application app = ac.Application;<br />
<br />
app.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;<br />
<br />
object filename = "myFile.rtf";<br />
object missingValue = Type.Type.Missing;<br />
<br />
Word.Document document = app.Documents.OpenOld(ref filename,<br />
ref missingValue, ref missingValue, <br />
ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue);<br />
<br />
app.ActivePrinter = "My Printer Name";<br />
<br />
object myTrue = true;
object myFalse = false;<br />
<br />
m_App.ActiveDocument.PrintOutOld(ref myTrue, <br />
ref myFalse, ref missingValue, ref missingValue, ref missingValue, missingValue, ref missingValue, <br />
ref missingValue, ref missingValue, ref missingValue, ref myFalse, ref missingValue, ref missingValue, ref m_MissingValue);<br />
<br />
document.Close(ref missingValue, ref missingValue, ref missingValue);<br />
<br />
while(m_App.BackgroundPrintingStatus > 0)<br />
{<br />
System.Threading.Thread.Sleep(250);<br />
}<br />
<br />
app.Quitref missingValue, ref missingValue, ref missingValue);<br />
I do not claim that this is perfect, but it's as good as I can get. It works on my machine anyway
|
|
|
|
|
You might want to write up an article for this instead. Your post will be knocked off the first page of this forum in less than a day.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Cheers. I've just done that. I wasn't sure how useful somethign like this is and there is already some similar code on here, but it's awful to read. Plus I am hoping that people will point out any flaws in the code as I am pretty sure it doesn't work perfectly
|
|
|
|
|
Hi,
I am trying to write some dynamic data into a .def file and havent succeeded to get enough help anywhere. Can u plz help me out here. HOW CAN I CREATE A .DEF FILE IN .NET(C#)
Thanks
Bharath
|
|
|
|
|