|
Hi
I have modified the code...Still the color does not change
String fr = Encoding.ASCII.GetString(data);
if (fr.Equals( "Welcome to the Server"))
{
lb9.BackColor = Color.Green;
}
|
|
|
|
|
Hi,
is the statement lb9.BackColor = Color.Green; being executed at all? check either by single-stepping or by adding some observation statement (Console.WriteLine("green")) inside the code block.
If it is and it does not show, here are several possible reasons:
- your code is not running on the main thread (then lb9 needs InvokeReqruied/Invoke)
- your code is followed by something that takes long or forever, and sits in an event handler (such as a button click); the GUI effects will show only when its done unless you insert an Applications.DoEvents() which is just a hack, not a recommendation.
- your code is followed by something that changes the color back before the GUI had an opportunity to show the changes.
Learn to debug: add observational code (logging, tracing, MessageBox, Console.WriteLine, whatever) and/or single-step.
Luc Pattyn [Forum Guidelines] [My Articles]
- 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 the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 9:12 AM
|
|
|
|
|
mrithula8 wrote: String fr
Just changing your variable name rarely affects the outcome of your code. Just as naming your dog one name vs another the dog is still the same dog.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Expert Coming wrote: Just changing your variable name rarely affects the outcome of your code. Just as naming your dog one name vs another the dog is still the same dog.
I'm going to have to remember that!
|
|
|
|
|
Hi,
just reread your post and now noticed text and code don't match, have a look at the casing of "Welcome" and "Server". You may want to perform a case-insensitive compare, e.g. by using string.Compare(... , ... , true)
Luc Pattyn [Forum Guidelines] [My Articles]
- 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 the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Saturday, March 7, 2009 4:08 PM
modified on Sunday, June 12, 2011 9:12 AM
|
|
|
|
|
Hi
The message "Welcome to the Server" is sent by the server and is displayed in the listbox.The color of the label changes with a click of the item "Welcome to the Server" in the listbox.But my requirement is that the color of the label should change when the message "Welcome to the Server" is sent from the server and is displayed in the listbox control and not with a click of the listbox item...Is that possible?Can you please tell me how i can go about this?
private void listBox3_Click(object o, EventArgs e)
{
Object df = listBox3.SelectedItem;
String kl = (String)df;
if (kl == "Welcome to the Server")
{
lb9.Text = "Active";
lb9.BackColor = Color.Green;
}
else
{
lb9.Text = "Inactive";
lb9.BackColor = Color.Red;
}
}
|
|
|
|
|
Hi,
1.
AFAIK there is no ListBox event firing when something gets added to its Items, so you will have to modify the code that adds stuff to the ListBox.Items, which probably resides in an event-driven handler anyway (some kind of DataReceived handler I would hope).
2.
The code shown is wrong and ugly for several reasons:
- ListBox.SelectedItem can be null (when nothing is selected), in which case you are switching to Inactive;
- once the server is active, it probably will add more stuff to the ListBox, and everytime that a some new line is clicked, assuming it is different from "Welcome to the Server" it will again declare an inactive state. Remedy: check on the presence of something that signifies end of session.
- what happens if the "Welcome to the Server" message changes for some reason, say extra spaces, carriage returns, etc? Checking for an exact match isn't probably not very wise, I would at least doif (kl.ToLower().Contains("welcome to the server"))...
Luc Pattyn [Forum Guidelines] [My Articles]
- 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 the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 9:12 AM
|
|
|
|
|
I have an application that queries records from a Visual FoxPro 8.0 table. I created an install project for this application an included the Vfpoledb merge module. When running the installed application on the development computer everything works fine. But when I install it on a Vista computer and try running it comes back with the error 'Cannot register Vfpoledb.1'. I'm installing it under the admin account. Any ideas on how to fix this problem? Thanks.
|
|
|
|
|
hi,
i wanna ask for how to make the .exe file run automatic after finish copy it from a location to another location. the exe file will run automatic without double click on it..
thanks..
- tyrone
|
|
|
|
|
If you mean the exe that is your application then you can't.
If you're moving an exe file within your application, then you can use the System.Diagnostics.Process class and it's Start method to start the exe.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Your can use your code to start it:
System.Diagnostics.Process.Start(anotherlocation+filename);
|
|
|
|
|
Anybody help me
In my application create a clock grid, the clock grid means the 24x7 clock(label) are formed a grid view, so i used the label, the label for every
cell, so totally 168 label are created in a one clock grid,
The two clock grid are created dynamically when the button
will be clicked.
My problem is that take lot time to loading and the GUI
blinking
How can handle this problem or give any other solution to
create this clock grid
Please Help me....
Thank you...
|
|
|
|
|
Create a Control and do your own drawing instead of using 168 labels!
If you've never created one before it's pretty easy. The code below will simply draw the control's Text at it's point 0, 0 using it's ForeColor and Font properties - and sets the default size for the control to 100, 100.
You can use this as a base to get started.
using System.Drawing;
using System.Windows.Forms;
public class ClockGrid : Control
{
public ClockGrid()
{
Size = new Size(100, 100);
}
protected override void OnPaint(PaintEventArgs e)
{
Point textPoint = new Point(0,0);
using (Brush brush = new SolidBrush(ForeColor))
{
e.Graphics.DrawString(Text, Font, brush, textPoint);
}
base.OnPaint(e);
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
anishkannan wrote: 168 label
Wouldn't it do displaying a Digital clock with time like 08:02:10 ?? You could easily show date too (08:02:10 08-March-2009)
|
|
|
|
|
TRy not to use so many controls since they consume a lot of resources.
To test the true performance use Release mode and not DEBUG mode.
There are plenty of articles discussing custom controls and overriding OnPaint.
Here is a small sample:
///
/// A custom control
///
public class MyUserControl : UserControl
{
#region Constructors and Initializers
///
/// Initializes the <c>ChartControl.
///
public MyUserControl()
{
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.Opaque, true);
UpdateStyles();
InitializeComponent();
}
#region Event Overrides
protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
{
//Do Nothing
}
protected override void OnPaint(PaintEventArgs args)
{
//Paint logic (first call graphics.Clear(BackgoundColor)
// Start drawing
}
#endregion
}
Natza Mitzi
|
|
|
|
|
Hi Folks,
I want to insert 6 rows of data of Six week days into SQL Server 2008 database from a single C# windows form. I want to use a data grid view....... Please suggest how to logically achieve it....on single click of "Save" button in bindingnavigator i want to insert all 6 records in
Database. I am using Visual Studio 2008 SP1.... pls help
regards
shafi
|
|
|
|
|
hmmm pie
|
|
|
|
|
Hello Friends,
How can i change the size of an Array at runtime in C#.Net.
In VB.Net, i can do it using "ReDim" & "Preserve" keywords.
Is there anything similar in C#.Net, so we can change the size at runtime?
Thanks and Regards,
Nagendra.
|
|
|
|
|
|
Can we use MultiDimensional ArrayList?
|
|
|
|
|
I hope multidimensional arraylist can be done by, Each element of the ArrayList would then be another ArrayList.
ArrayList a = new ArrayList();
a.Add(new ArrayList());
|
|
|
|
|
ok thanks, i'll try this.
|
|
|
|
|
Hi,
In all .NET languages one-dimensional arrays can be resized, see the Array.Resize() method in the documentation. "This method allocates a new array with the specified size, copies elements from the old array to the new one, and then replaces the old array with the new one."
When you need to resize an array several times, or if you just don't know what size to choose at the start, you are probably better off choosing another kind of collection. The old ArrayList still exists, but it is better to use a generic list (that's List<T> ) which provides type checking and better performance. These collections grow and shrink dynamically without copying their content [ADDED] all the time (in the current implementation they grow by rounding up their capacity to the next power of 2 and copying only then).[/ADDED]
Luc Pattyn [Forum Guidelines] [My Articles]
- 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 the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 9:13 AM
|
|
|
|
|
Actually List<t> does copy all its elements when it needs to grow.
Go to System.Collections.Generic.List<t>.set_Capacity(int value) in for example Red Gate's .NET Reflector..
|
|
|
|
|
Right. I keep forgetting that. Back to the home-made linked lists then.
Luc Pattyn [Forum Guidelines] [My Articles]
- 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 the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 9:13 AM
|
|
|
|