|
Using Win32 resources is not particularly complicated in general, but the .Net Framework does not have stellar legacy support built in.
See the link in my initial post, using ResourceWriter and ResourceReader. It should do exactly what you're suggesting, and provides examples for how to read from and write to .resources files.
You can put more than one resource in a .resources file; they are added in key/value pairs.
Good luck.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
OK thanks for all your help
I will try getting this working using your original post
|
|
|
|
|
I have two TextBoxes. I have a button that calls a method that will use the
input from the text boxes ONLY if a number is entered. How do I do I do this?
Tried for several nights-- but I keep crashing on non-numerical input...
--thanks in advance
|
|
|
|
|
Void OnButtonClick(...)
{
Try
{
int i = Convert.ToInt(textbox.Text);
}
catch
{
return
}
DoSomething();
}
|
|
|
|
|
Dan- thanks. I have already tried the code you've shown. My problem is that BOTH text boxes are "tied" to the button event-- so I keep getting an infnite loop of two MessageBoxes (each from the catch statements of the two TextBoxes)
when there is an invalid entry....
|
|
|
|
|
I'm not sure I follow you here. Are you doing your check event when the button is clicked, or when a user modifies the content of eitehr box?
|
|
|
|
|
Ok Here's what I did...program crashes on invalid input and I get endless Message boxes that won't close on 'OK'. Thanks...
This is driving me nuts....
///////////////////////////////
void DrawComplexNumber1(Graphics g)
{
Pen p = c_xy.GetNextPen();
p.DashStyle = DashStyle.Dot;
c_xy.SetOrigin(xIndent + graphRect.Width/2, yIndent + graphRect.Y/2);
try
{
cmplxValue1.Real = Convert.ToDouble(textComplex_1Real.Text);
}
catch
{
MessageBox.Show("Error!");
}
try
{
cmplxValue1.Imaginary = Convert.ToDouble(textComplex_1Imaginary.Text);
}
catch
{
MessageBox.Show("Error!");
}
g.DrawLine(p, 250, 250, (float)(250 + (xIndent * cmplxValue1.Real)), (float)(250 - (yIndent * cmplxValue1.Imaginary)));
//////////////////////////////////////////////
private void complex_1OK_Click_1(object sender, System.EventArgs e)
{
drawLine1 = !drawLine1;
Invalidate();
}
/////////////////////////////////////////Paint Handler
....
if(drawLine1)
DrawComplexNumber1(e.Graphics);
}
|
|
|
|
|
hi
How about using int32.parse(textbox.text) ?
Banshi Khinchi
|
|
|
|
|
You see the following code :
private void button1_Click(object sender, System.EventArgs e)
{
int number = 0;
try
{
number = System.Convert.ToInt32(textBox1.Text);
}
catch(Exception ex)
{
System.Windows.Forms.MessageBox.Show("Input is not a number !");
textBox1.Focus();
return;
}
DoSomething(number);
}
private void DoSomething(int iNumber)
{
// Your code is here ...
}
with textBox1, textBox2 are two instances of TextBox class and button1 is a instance of Button class.
NPS.
|
|
|
|
|
Handle the Validating event for both text boxes:
private void TextBox_Validating(object sender, CancelEventArgs e)
{
TextBox textBox = sender as TextBox;
if(textBox == null)
return;
if(textBox.TextLength == 0)
return;
bool error = false;
try
{
int n = Convert.ToInt32(textBox);
if(n < 0 || n > 100)
error = true;
}
catch(FormatException)
{
error = true;
}
finally
{
if(error)
{
MessageBox.Show("Please enter a valid number");
textBox.SelectAll();
textBox.Focus();
e.Cancel = true;
}
}
} When the user tries to take focus away from the control, its contents will be validated. If invalid, the user won't be allowed to leave the control unless he corrects it or leaves it empty.
Then in you button handler, just validate that the text boxes have anything. If they do, it's surely a valid number.
I hope this helps!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
In keypress of textbox-es write this code:
e.Handled = e.KeyChar < '0' || e.KeyChar > '9';
u are able to write only numers no other charachters
I hope this helps u
|
|
|
|
|
I have a value in the ComboBox that does not appear in its drop down list. When I drop down the list, I want the nearest match to be selected without changing the current value.
So far I have a custom control that I inherited from System.Windows.Forms.ComboBox, and I have the following code attempting to do this.
protected override void OnDropDown(EventArgs e)
{
string strValue = this.Text;
int nValue = Convert.ToInt32(strValue);
for (int i = 0; i < this.Items.Count; i++)
{
int nItem = Convert.ToInt32(this.Items[i].ToString());
if (nValue >= nItem && nValue < nItem + 50)
{
this.SelectedIndex = i;
break;
}
}
base.OnDropDown(e);
this.Text = strValue;
}
If I remove "this.Text = strValue;", the nearest value is selected however the Text property will now contain this new selected value. I want to select the nearest value when the list drops down (for display purposes), but at the same time retain the value in the Text property.
--IAN
|
|
|
|
|
Hope this helps...........
private string buffer = String.Empty;
private Timer timer = null;
const int MAX_BUFFERSIZE = 1024;
this.timer = new Timer();
this.timer.Interval=1000;
this.timer.Tick+=new EventHandler(this.TimerTick);
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.OnKeyPress);
public void TimerTick(object sender,EventArgs eArgs)
{
this.buffer = String.Empty;
this.timer.Stop();
}
protected void OnKeyPress(object sender, KeyPressEventArgs e)
{
try
{
e.Handled = true;
if ( this.buffer.Length == 0 )
{
timer.Start();
}
if ( buffer.Length < MAX_BUFFERSIZE )
{
buffer += e.KeyChar.ToString();
Console.WriteLine(buffer);
}
int startIndex = 0;
if ( this.SelectedIndex != -1 )
{
startIndex = this.SelectedIndex;
}
bool found = false;
for ( int index = startIndex; index <= this.Items.Count - 1; index++)
{
string text = String.Empty;
if ( this.DisplayMember != String.Empty )
{
PropertyInfo propertyInfo = base.Items[index].GetType().GetProperty(base.DisplayMember);
text = propertyInfo.GetValue(base.Items[index], null).ToString();
}
else
{
text = base.Items[index].ToString();
}
if ( text.Length > this.buffer.Length )
{
if ( text.ToUpper().StartsWith(buffer.ToUpper()))
{
found = true;
this.SelectedIndex = index;
break;
}
}
}
if ( !found )
{
for ( int index = 0 ; index < startIndex; index++)
{
string text = String.Empty;
if ( this.DisplayMember != String.Empty )
{
PropertyInfo propertyInfo = base.Items[index].GetType().GetProperty(base.DisplayMember);
text = propertyInfo.GetValue(base.Items[index], null).ToString();
}
else
{
text = base.Items[index].ToString();
}
if ( text.Length > this.buffer.Length )
{
if ( text.ToUpper().StartsWith(buffer.ToUpper()))
{
this.SelectedIndex = index;
break;
}
}
}
}
}
catch ( Exception ex )
{
Console.WriteLine(ex.Message);
}
}
|
|
|
|
|
Unfortunately I'm not looking for autocomplete type of functionality.
Let's say that combo box list contains times of the day in half hour increments (12:00 am, 12:30 am, 1:00 am, ...). This allows for easy selection of a time. However the user needs to be allowed to enter a time that does not appear in the list, say 1:09 am (and actually by default will be loaded with the current time). This is all easy to do, and does not require any extraordinary coding.
Now for the tricky part. Let's say the combo box has a value of, say 3:12 pm. When the user clicks to drop down the list, the value 3:12 pm will not be found in the list, so it will be positioned with 12:00 am as the first item in the drop down list. Just as a nice to have, I'd like to see the list "auto-scroll" to the nearest value contained in the list when the list is dropped down. In this case it would be 3:00 pm. In addition, at the same time as we are "auto-scrolling", we need to retain the original value of 3:12 pm in the combo box. I know, quite a challenge.
Microsoft currently has this type of functionality in Outlook when setting up a new appointment on the Calendar. If they can do, should we be able to do it?
--Ian
|
|
|
|
|
I have a solution to my post, and here it is.
<br />
public class TimePicker : ComboBox<br />
{<br />
bool m_fIsDropDown = false;<br />
string m_strTime = string.Empty;<br />
int m_nSelectedIndex = -1;<br />
<br />
<br />
public TimePicker() : base()<br />
{<br />
}<br />
<br />
private void LoadTimes()<br />
{<br />
if (this.Items.Count < 1)<br />
{<br />
DateTime t = new DateTime(2005, 10, 11, 0, 0, 0, 0);<br />
while (t < new DateTime(2005, 10, 12))<br />
{<br />
this.Items.Add(t.ToShortTimeString());<br />
t = t.AddMinutes(30);<br />
}<br />
}<br />
}<br />
<br />
protected override void OnCreateControl()<br />
{<br />
base.OnCreateControl();<br />
<br />
LoadTimes();<br />
}<br />
<br />
protected override void OnDropDown(EventArgs e)<br />
{<br />
base.OnDropDown(e);<br />
<br />
m_strTime = this.Text;<br />
DateTime dtmValue = DateTime.Now;<br />
try <br />
{<br />
dtmValue = Convert.ToDateTime(m_strTime);<br />
}<br />
catch <br />
{<br />
return;<br />
}<br />
<br />
for (int i = 0; i < this.Items.Count; i++)<br />
{<br />
DateTime dtmItem = Convert.ToDateTime(this.Items[i].ToString());<br />
if (dtmValue >= dtmItem && dtmValue < dtmItem.AddMinutes(30))<br />
{<br />
this.SelectedIndex = i;<br />
m_nSelectedIndex = i;<br />
break;<br />
}<br />
}<br />
<br />
m_fIsDropDown = true;<br />
}<br />
<br />
protected override void OnMouseDown(MouseEventArgs e)<br />
{<br />
if (m_fIsDropDown == true)<br />
{<br />
this.SelectedIndex = m_nSelectedIndex;<br />
this.Text = m_strTime;<br />
}<br />
else<br />
{<br />
base.OnMouseDown(e);<br />
}<br />
}<br />
<br />
protected override void OnMouseUp(MouseEventArgs e)<br />
{<br />
if (m_fIsDropDown == true)<br />
{<br />
this.SelectedIndex = m_nSelectedIndex;<br />
this.Text = m_strTime;<br />
m_fIsDropDown = false;<br />
}<br />
else<br />
{<br />
base.OnMouseUp(e);<br />
} <br />
}<br />
} <br />
--IAN
|
|
|
|
|
is there a way to hide a process from System.Diagnostics.GetProcesses()? so it would not list it? or if its listed not be able to access its information?
also is there a way to tell which process is attempting to hook to yours? or is attempting to access yours?
so if i say:
Within Process "B"
{
System.Diagnostics.Process tProcess = System.Diagnostics.GetProcessByName("B");
event(System.Diagnostics.Process pAnotherProcess)// when another process is accessing yours
{
if(pAnotherProcess.ProcessName == "B")
Message("your accessing your own process");
}
}
i know this might be C++ section but just want to find out what i need to do to detect this?
or away to catch any calles to get process information.
CALLER-->GetProcess()-->RedirectToMyFunction-->Pass/Reject Request-->CALLER
-- modified at 11:13 Thursday 13th October, 2005
|
|
|
|
|
mishen` wrote: is there a way to hide a process from System.Diagnostics.GetProcesses()? so it would not list it?
No.
mishen` wrote: or if its listed not be able to access its information?
Process Security and Access Rights[^]. You'll have to P/Invoke a bunch of functions and structures to alter your process' ACL. There is nothing in the .NET BCL (1.0 and 1.1) that supports this.
mishen` wrote: also is there a way to tell which process is attempting to hook to yours?
No.
mishen` wrote: or is attempting to access yours?
No.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
thanks for being streight forward.
so most questions answered thanks. most glad that the process cant tell if your hooking to it.
thanks for he link.:->
|
|
|
|
|
Hi all,
i have a rich textbox and i want that the richtextbox
should be of A4 size i.e. it should accommodate contents
that of A4 size
the user should not be able to enter text if the contents
have reached the A4 limits
Please if anyone of you could help me
Thanks
Pramod
|
|
|
|
|
Hi!
I want my application to close if the user is not performing any keyboard or mouse activity and no process (copying file, query database etc.) is running for 5 minutes.
Can somebody how can I do this?
Thank You
|
|
|
|
|
|
I think it works for Keyboard and Mouse activities only but what about the running processes in my application i.e. read/write files or any non-idle process.
|
|
|
|
|
I want my application to trigger on external application start/close events but haven't been able to figure out how to do this.
For example. I would like my application to execute a certain task every time Internet Explorer is executed on the system.
I would greatly appreciate if someone had a solution to this!
Thanks!
// T
|
|
|
|
|
Well, one way you could do this (which isn't the best way I don't imagine, but I can't think of any other way at the moment) is to create a task watcher process that watches the task list and kicks off event "alerts" that you set when certain tasks are created/exited.
|
|
|
|
|
Yes, this is how I do it now..
I don't feel that this is the correct way of doing it though. I would imagine that you could hook on IE or trap a windows message to do this instead. I've tried searching for it on the net and haven't found anything
Hopesfully someone will have a solution
|
|
|
|