|
jtmtv18 wrote:
i havent tryed that yet but not sure if it will work if it wont can someone help me with this subject ?
This seems to work for me:
private void button1_Click(object sender, System.EventArgs e)
{
string s;
s = Environment.CurrentDirectory.ToString();
System.Diagnostics.Process.Start(s);
}
You will need to identify the folder you want as a string field however, which you didn't do above.
Nick Parker
You see the Standards change. - Fellow co-worker
|
|
|
|
|
Have someone any www.learnvisualstudio.net videos?
If you want we can exchange some videos.
gicio
|
|
|
|
|
Hi,
I develop an application that have 20 windows forms with many TextBoxes.
All TextBoxes have the same validation...
I write in all classes the same validation like that:
[CODE]
//if the user press a key down at txtDisplacement we check which one was pressed down
#region KeyDownInTxtDisplacement code
private void KeyDownInTxtDisplacement(object sender, System.Windows.Forms.KeyEventArgs e)
{
CheckWhichKeyDown(e);
}
#endregion
//if the user press a key down at txtModel we check which one was pressed down
#region KeyDownInTxtModel code
private void KeyDownInTxtModel(object sender, System.Windows.Forms.KeyEventArgs e)
{
CheckWhichKeyDown(e);
}
#endregion
//we check which key is pressed
//if key Enter or Return or Tab is pressed
//we go throw DoWhenOneTextBoxIsMarkedRed()
#region CheckWhichKeyDown code
private void CheckWhichKeyDown(System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode==Keys.Enter || e.KeyCode==Keys.Return || e.KeyCode==Keys.Tab)
{
ValidateThis();
}
}
#endregion
//when special key is press we enable the button
#region ValidateThis code
private void ValidateThis()
{
cmdAddToDataBase.Enabled = true;
}
#endregion
[/CODE]
CheckWhichKeyDown and ValidateThis should be in one validation class.
How I can write a validation class that validate ALL TextBoxes from all classes.
Any ideas?
Or do you know some sample validation classes available on www?
gicio
|
|
|
|
|
gicio wrote:
CheckWhichKeyDown and ValidateThis should be in one validation class.
How I can write a validation class that validate ALL TextBoxes from all classes.
Any ideas?
Sure, I would highly suggest this so you aren't rewriting code all the time, simply add a new class within your application, possibly like the following:
namespace test
{
public class Validation
{
public Validation()
{}
public bool CheckWhichKeyDown(System.Windows.Forms.KeyEventArgs kea)
{
if(kea.KeyValue == 13)
return true;
else
return false;
}
public bool SomeOtherFunctionHere()
{
return true;
}
}
}
Then, say for example in any of your KeyDown event handlers you can implement it like the following, keep in mind my namespace for this example is titled test.
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
test.Validation v = new Validation();
if(v.CheckWhichKeyDown(e) == true)
MessageBox.Show("You hit enter.");
else
MessageBox.Show("You hit " + e.KeyData.ToString());
}
The idea is that you are creating an instance of a class, your validation class, and then invoking methods against that instance. Hope this helps.
Nick Parker
You see the Standards change. - Fellow co-worker
|
|
|
|
|
thanks for this great solution!!!
gicio
|
|
|
|
|
no problem, hope it helps.
Nick Parker
You see the Standards change. - Fellow co-worker
|
|
|
|
|
|
Hi,
I write a new class... like this:
[CODE]
using System;
using System.Windows.Forms;
using System.Windows.Forms.ComponentModel;
namespace CarTrade
{
///
/// Summary description for TestTextBox.
///
public class TestTextBox : System.Windows.Forms.TextBox
{
private bool booOnlyNumericCharsAllowed;
private bool booSpecialKeyIsPress;
public TestTextBox.
{
}
//---------------------------------------------------------------
//---------------------------PROPERTIES--------------------------
//---------------------------------------------------------------
//we allowed in the TestTextBox only numeric chars
//when the user set the proparty OnlyOnlyNumericCharsAllowed
//to true
internal bool OnlyNumericCharsAllowed
{
get
{
//return the value how OnlyOnlyNumericCharsAllowed
//is set
return booOnlyNumericCharsAllowed;
}
set
{
if(value)
{
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.DoWhenKeyPress);
}
booOnlyNumericCharsAllowed = value;
}
}
internal bool SpecialKeyIsPress
{
get
{
return booSpecialKeyIsPress;
}
set
{
if(value)
{
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.CheckIfSpecialKeysArePressed);
}
booSpecialKeyIsPress = value;
}
}
private void CheckIfSpecialKeysArePressed(object sender, System.Windows.Forms.KeyEventArgs e)
{
bool booEnter = e.KeyCode == Keys.Enter;
bool booReturn = e.KeyCode==Keys.Return;
bool booTab = e.KeyCode==Keys.Tab;
if(booEnter || booReturn || booTab)
{
}
}
private void DoWhenKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 )
{
e.Handled = true;
}
if(Text.Length == 0 && e.KeyChar == 48)
{
e.Handled = true;
}
}
}
}
[/CODE]
Any coments are welcome!
gicio
|
|
|
|
|
Hi,
do you know other developer boards?
special C# and VB and C++
gicio
|
|
|
|
|
Hi,
I'm looking for developer videos/demos/webcasts tutorials
for c#, VB.NET, VB, C++, JAVA, UML, Rational rose, XML, XSLT, SQL and other
development stuff.
I know right now only the microsoft webcasts and the stuff from
www.learnvisualstudio.net do you know others?
gicio
|
|
|
|
|
Here:
http://www.banasoft.net/avphone3/demos/sourcedemo.htm
|
|
|
|
|
I need to invoke a methods using reflection. I don't know how to get the variable reference so I can invoke the methods with 'ref' parameter. Same problem with 'out'.
|
|
|
|
|
The parameteres you pass to the invoke method are put in an object[]. When you call a function with a ref or out parameter, the value will come back as part of that array.
|
|
|
|
|
Hey. I have a main form which uses a modal dialog box. When the user hits a button on the modal dialog I then proceed to close the modal dialog and return to the main form..
I am closing the modal dialog box from inside itself. OnbuttonClick();
ie ... OnButtonClick()
{
this.Close();
}
It gives me this!
An unhandled exception of type 'System.InvalidOperationException' occurred in system.windows.forms.dll
Additional information: Forms that are already displayed modally cannot be displayed as a modal dialog. Close the form before calling showDialog.
I have no clue why it isn't working.. If anyone could help it would be hugely appreciated. Thanks..
|
|
|
|
|
this.DialogResult = DialogResult.Cancel; is enough to do the trick.
|
|
|
|
|
Even when i do that is still throws an error...
What I am doing is I have my main form.. My main form calls .ShowDialog() of another form... and then that form calls .ShowDialog() again.
So i have a my main window which calls show and then the new window calls show
When i do: this.DialogResult = DialogResult.Cancel;
You can see it close the appropriate form but then it throws an error.
Please help.. Thanks...
|
|
|
|
|
Basically what I am doing is a touch screen application.. And each modal dialog of a form ie. .ShowDialog is an attempt to show a new screen to the user.. So I have my main form with some buttons and the user clicks a button.. This brings the user to a new screen or form. And when the user clicks another button on that form it brings him to another form.
What would be the best way to go about displaying these forms? They have to be forms.. Cause I am using the opacity of the forms to do fading from screen to screen.. But if the user wants to go back to a previous form. I need a way to close the form without some error like I am getting now.
If anyone could help.. It would be the hugest help..
Thanks so much.
|
|
|
|
|
Why is this modal at all ? If you need a sequence of forms with clickable buttons, you just need to show the forms. I recommend you replace all those .ShowDialog() calls with simple .Show() calls.
|
|
|
|
|
Thanks so much for sticken with me on this...
Okay the thing is the modal forms are mostly transparent in nature.. With only the buttons being visible. It's kinda weird but it's for a theme I am going with on this touchscreen. To do fading in and out and have the buttons at half opacity. If the form isn't modal and the transparent part of the form get's clicked the form will actually lose focus and the form below it will end up receiving the click event. This is not good.
I guess my example might be kinda complex.. I have a main form Form1. which then loads a graphics screen [Form2] which fades from the main screen to itself going from 0 to 100 opacity. Then the buttons on a transparent form[which are actually just pictureboxes set up to act like buttons] fade in over Form3 but only to 60% opacity.
See now if the user was now to use the touchscreen in this state and the user was to touch something that wasn't a button on Form3 [ie. the transparent area]. The event would not be caught by Form3 but by Form2.
Which means Form3 now lost it's focus.
I am going isane trying to figure this out. If you could help me I can't even explain how helpful that would be.
Thanks very much.
Steve
|
|
|
|
|
gekoscan wrote:
If the form isn't modal and the transparent part of the form get's clicked the form will actually lose focus and the form below it will end up receiving the click event
That's where I don't see why you don't handle the focus yourself with a non-modal Form. Even with a non-modal Form, you can subscribe to a lot of Form or simple control events and act accordingly.
The trouble with modal Forms is they have each a running ThreadContext attached to it, so you've got to either :
- let the modal Form workflow work as expected, (even if you add a few tweaks such as the DialogResult stuff)
- hack the ThreadContext to make sure internals are properly synchronized (so you don't end up with an exception).
- or simply catch those exceptions with a try{}catch(){} container (!)
All of this sounds ugly enough to me.
|
|
|
|
|
i want to send some messages programatically to all computers of the network using
some socket programming and a perticuler port say (999).
is it possible that i send this message using broadcaste ip like 192.168.0.255:999.
when i use this command on command prompt then it sends message on all computers of the network
------------------------
net send * some message
------------------------
in the above command what does * means?
what is the value of this ip address is?
r00d0034@yahoo.com
|
|
|
|
|
The best thing here IMO would be to use a multicast sender/reciever.
mcastSend.cs
using System;
using System.Net;
using System.Net.Sockets;
namespace multiCastSend
{
class send
{
send(string mcastGroup, string port, string ttl, string rep)
{
IPAddress ip;
try
{
Console.WriteLine("MCAST Send on Group: {0} Port: {1} TTL: {2}",mcastGroup,port,ttl);
ip=IPAddress.Parse(mcastGroup);
Socket s=new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
s.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.AddMembership, new MulticastOption(ip));
s.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.MulticastTimeToLive, int.Parse(ttl));
byte[] b=new byte[10];
for(int x=0;x<b.Length;x++) b[x]=(byte)(x+65);
IPEndPoint ipep=new IPEndPoint(IPAddress.Parse(mcastGroup),int.Parse(port));
Console.WriteLine("Connecting...");
s.Connect(ipep);
for(int x=0;x<int.Parse(rep);x++)
{
Console.WriteLine("Sending ABCDEFGHIJ...");
s.Send(b,b.Length,SocketFlags.None);
}
Console.WriteLine("Closing Connection...");
s.Close();
}
catch(System.Exception e) { Console.Error.WriteLine(e.Message); }
}
static void Main(string[] args)
{
new send("224.5.6.7", "5000", "1", "2");
}
}
}
mcastRecv.cs
using System.Net.Sockets;
using System.Net;
using System;
namespace multiCastRecv
{
class recv
{
recv(string mcastGroup, string port)
{
Socket s=new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint ipep=new IPEndPoint(IPAddress.Any,int.Parse(port));
s.Bind(ipep);
IPAddress ip=IPAddress.Parse(mcastGroup);
s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ip,IPAddress.Any));
while(true)
{
byte[] b=new byte[10];
Console.WriteLine("Waiting for data..");
s.Receive(b);
string str = System.Text.Encoding.ASCII.GetString(b,0,b.Length);
Console.WriteLine("RX: " + str.Trim());
}
}
public static void Main(string[] args)
{
new recv("224.5.6.7","5000");
}
}
}
WebBoxes - Yet another collapsable control, but it relies on a "graphics server" for dynamic pretty rounded corners, cool arrows and unlimited font support.
|
|
|
|
|
Hi all,
I am creating a custom user control (inherited from the UserControl class), and I would like to mimic the behaviour of the standard Button control.
When you set the Text property of the Button to '&Close', the button shows: 'Close'. When you press ALT+C when the form is active, the button will receive a click event.
Does anyone has an idea about how to accomplish this?
Greetz,
Jan
|
|
|
|
|
|
Thanx for your reply. But I want to have all the needed code in my new User Control, just like the standard button.
When you place a standard button on a form, and set the the text to '&Close', the click event will be called whenever the alt+c keys are pressed (and the form has focus). Even if the current focus is in a textbox on that form for example.
Any idea's??
Jan
|
|
|
|