|
|
Hello,
I'm working in MS Visual C# 2005 Express.
I recently stumbled upon a nice "vista-like" button class posted here on codeproject.
http://www.codeproject.com/KB/miscctrl/VistaButton.aspx[^]
It's worked fine for one of my projects, except that I cannot set the DialogResult on one of those custom buttons, like you can a regular button.
I'm trying to add it manually into the vistabutton User Control but I have no luck so far. This is what I have added:
private DialogResult dResult = DialogResult.OK;<br />
<br />
public DialogResult DialogResult<br />
{<br />
get { return DialogResult.OK; }<br />
set { dResult = value; }<br />
}
And i'm trying to use it like this in my designer code:
this.button8.DialogResult = System.Windows.Forms.DialogResult.OK;
I'm still a newb coder, can someone point out my errors? It compiles and runs fine.. but doesn't return the dialogresult
|
|
|
|
|
Ok, I made a few changes but it still does not seem to work.
private DialogResult dResult = DialogResult.None;<br />
<br />
public DialogResult DialogResult<br />
{<br />
get { return dResult; }<br />
set { dResult = value; }<br />
}
|
|
|
|
|
The form's DialogResult property needs to be set to the button'd DialogResult property when clicked so in the button8 Click event enter this code
this.DialogResult = button8.DialogResult;
Dave
|
|
|
|
|
Yes! That was it. Thanks!!
|
|
|
|
|
My project just stop to run my recent changes, it continues running and earlier version of my project
it means, not matter what kind of changes I do to my code, the earlier version still run.
Before this estrange behavior, every time a make a mistake a message box appear and ask about run the last running version or stop, but now the windows doesn't appear.
Regards
Rafael
Life is Great, and kids the best
|
|
|
|
|
Do a complete recompile. It sounds like you've got a bug in your code and Visual Studio is running the last known good build.
|
|
|
|
|
Hi,
I sometimes get the same behavior with VS2005 C# Express Edition, seems like a bug
in Visual; in my experience there are several ways that typically solve it:
- perform a clean build (Menu Item "Build/Rebuild Solution")
- delete the entire "bin" and "obj" directories in the project folder; first check
they contain output files only, your input files (source files, resources) should
not be there! Then rebuild.
- reboot and build again.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- 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 PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I am trying to mimic the operation of a temperature transmitter that streams data via UDP. So, currently I have a program that sends data every second. For some reason, in my receive program, I receive each packet twice. Once from the correct IP address and the wrong port, and secondly from 0.0.0.0 ip address and the right port (8000). Here is my code. Does anyone have any suggestions?
// defined as a member of the form
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
private void Form1_Load(object sender, System.EventArgs e)
{
EndPoint ipep = new IPEndPoint(IPAddress.Broadcast, 8000);
s.Connect(ipep);
}
private void timer1_Tick(object sender, System.EventArgs e)
{
// ignore the string part for now
string strLine = (string)lstData[cnt++];
if (cnt == lstData.Count)
cnt = 0;
byte[] data = Encoding.ASCII.GetBytes(strLine);
s.Send(data);
}
Chase Davis
|
|
|
|
|
Chase Davis wrote: Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
Chase Davis wrote: EndPoint ipep = new IPEndPoint(IPAddress.Broadcast, 8000);
s.Connect(ipep);
Chase Davis wrote: s.Send(data);
I'm no expert with UDP but I think you are supposed to use Socket.SendTo(...)
Maybe this will help[^]
led mike
|
|
|
|
|
Actually, it works either way. With the Send function, I think you have to call the connect function. With the SendTo function, you don't have to connect, but you do have to set the SocketOption to Broadcast. Anyway, I tried using the SendTo function and I still see the same results. Thanks for the help though.
Chase Davis
|
|
|
|
|
Perhaps the problem is in the Receiving code which you have not posted?
led mike
|
|
|
|
|
Well, I thought about that. However, I used a program from the customer that monitors UDP data and the same thing happens. In any case, here is the receive code:
// local member of the form
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
private void btnStart_Click(object sender, System.EventArgs e)
{
// user defined class to contain socket information
StateObject state = new StateObject();
state.workSocket = s;
EndPoint ipep = new IPEndPoint(IPAddress.Any, Convert.ToInt32(txtPortNum.Text, 10));
// only bind if it has not been bound yet
if (s.LocalEndPoint == null)
s.Bind(ipep);
s.BeginReceiveFrom(state.buffer, 0, StateObject.BufferSize, SocketFlags.None, ref ipep, new AsyncCallback(OnReceive), state);
}
void OnReceive(IAsyncResult iar)
{
StateObject state = (StateObject)iar.AsyncState;
Socket client = state.workSocket;
EndPoint epRemote = new IPEndPoint(IPAddress.Any, Convert.ToInt32(txtPortNum.Text, 10));
int bytesRead = client.EndReceiveFrom(iar, ref epRemote);
string str = Encoding.ASCII.GetString(state.buffer);
// do stuff with the string
s.BeginReceiveFrom(state.buffer, 0, StateObject.BufferSize, SocketFlags.None, ref epRemote, new AsyncCallback(OnReceive), state);
}
Chase Davis
|
|
|
|
|
Chase, like I said I have had no experience with UDP so I just put together two apps, Sender and Client, they work as expected here is the code
Sender Application
public partial class Form1 : Form
{
private System.Net.Sockets.Socket _sock;
private System.Net.IPEndPoint _ipEnd;
public Form1()
{
InitializeComponent();
_sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPHostEntry hostent = Dns.Resolve(Dns.GetHostName());
_ipEnd = new IPEndPoint(hostent.AddressList[0], 3030);
}
private void button1_Click(object sender, EventArgs e)
{
byte[] bytes = Encoding.ASCII.GetBytes(textBox1.Text);
Cursor oldCursor = Cursor;
Cursor = System.Windows.Forms.Cursors.WaitCursor;
_sock.SendTo(bytes, _ipEnd);
Cursor = oldCursor;
}
}
Client application
public partial class Form1 : Form
{
UdpClient _client;
IPEndPoint _ipEndPoint;
public Form1()
{
InitializeComponent();
_ipEndPoint = new IPEndPoint(IPAddress.Any, 3030);
_client = new UdpClient(_ipEndPoint);
_client.BeginReceive(Recv, new State(_client, _ipEndPoint, this));
}
public void OnRecvMsg(string msg)
{
if( textBox1.Text.Length > 0)
textBox1.Text = String.Format("{0}\r\n{1}", textBox1.Text, msg);
else
textBox1.Text = msg;
}
public static void Recv(IAsyncResult ar)
{
State state = ar.AsyncState as State;
Byte[] bytes = state.Client.EndReceive(ar, ref state.EndPoint);
state.TForm.OnRecvMsg(Encoding.ASCII.GetString(bytes));
state.Client.BeginReceive(Recv, state);
}
}
internal class State
{
public IPEndPoint EndPoint;
public UdpClient Client;
public Form1 TForm;
internal State(UdpClient client, IPEndPoint endpoint, Form1 form)
{
EndPoint = endpoint;
Client = client;
TForm = form;
}
}
led mike
|
|
|
|
|
i want to build an application which can show all files sheared on my windows os
which property is peculiar to shared files within my system and how and from where can i access the properties of my windows files
|
|
|
|
|
Can you specify what means "shared files"?
led mike
|
|
|
|
|
files or folders on my system that i share to enable them to be accesible say over a network
|
|
|
|
|
|
Hi,
I am just testing some functions.
My question is how can I change the color of a LABEL, TAB texts on a form.
What I tried?
I created an xml file with the forecolor, backcolor info.
<color> <settings>
<label1>
<forecolor>> #FFFFFF
<backcolor> #FFFFFF
then I tried to link it.
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(46, 13);
this.label1.TabIndex = 0;
// this.label1.Text = "Test123";
this.label1.Text = xDoc.SelectSingleNode("Language/Settings/Label1/Text").InnerText.Trim();
this.label1.ForeColor = xDoc1.SelectSingleNode("Color/Settings/Label1/ForeColor").InnerText.Trim();
this.label1.BackColor = xDoc1.SelectSingleNode("Color/Settings/Label1/BackColor").InnerText.Trim();
and under my main class i have:
public Form1()
{
InitializeComponent();
//Load XML
xDoc1 = new XmlDocument();
xDoc1.Load(Application.StartupPath + @"\Application Data\DummyText.xml");
}
but its doesnt work like this, Summary : I want to change the color of the TEXTs on my form from an xml document. i know i need to use system.drawing.color somewhere.
modified on Monday, February 11, 2008 1:18 PM
|
|
|
|
|
s3rro wrote: I want to change the color of the TEXTs on my form from an xml document. i know i need to use system.drawing.color somewhere.
So you want to create a Color object from a hexstring representation of the color, yes?
Please NOTE this is without error checking and it is NOT a design.
string scolor = "#6633aa";
int red = Convert.ToInt16(scolor.Substring(1, 2),16);
int green = Convert.ToInt16(scolor.Substring(3, 2),16);
int blue = Convert.ToInt16(scolor.Substring(5, 2),16);
label1.ForeColor = Color.FromArgb(red, green, blue);
led mike
|
|
|
|
|
See ColorTranslator.FromHtml.
e.g
this.label1.ForeColor = ColorTranslator.FromHtml(xDoc1.SelectSingleNode("Color/Settings/Label1/ForeColor").InnerText.Trim());
|
|
|
|
|
Sweet, had not seen that before.
led mike
|
|
|
|
|
thanks man thats what i was looking for.
|
|
|
|
|
Very nice. I'd forgotten about that - thanks for the reminder.
Definitely worth the 5 that's winging its way to you.
|
|
|
|
|
Hi guys
I have a function called SendEmail which runs within a thread.
This function simply send an email to the user.
However, I made a "Please Wait..." page while the email gets send in the background the user see the "Please Wait..." page.
<br />
<br />
public void SendEmail()<br />
{<br />
StringBuilder messageText = new StringBuilder();<br />
<br />
messageText.AppendLine(string.Format("Name: {0} {1}", txtName.Text.Trim().ToString(), txtSurname.Text.Trim().ToString()));<br />
messageText.AppendLine(string.Format("Contact Number: {0}", txtContactNumber.Text.Trim().ToString()));<br />
messageText.AppendLine(string.Format("Email Address: {0}", txtEmail.Text.Trim().ToString()));<br />
messageText.AppendLine(string.Format("Comments: {0}\n\n", txtComments.Text.Trim().ToString()));<br />
messageText.AppendLine(string.Format("Quote Reference Nr: {0}", Request.QueryString["quoteNr"].ToString()));
<br />
}<br />
I call the SendEmail() function using the following lines of code:
<br />
Guid id = Guid.NewGuid();<br />
<br />
ThreadStart ts = new ThreadStart(SendEmail);<br />
<br />
Thread th = new Thread(ts);<br />
<br />
th.Start();<br />
<br />
Response.Redirect(string.Format("PleaseWait.aspx?ID={0}&type={1}", id, "email"));<br />
Is it true that you can't access Request data within a thread, if not, how do I then get access to Request.QueryString data?
|
|
|
|
|