|
I am trying to access a listbox in a class that is not Form1.cs but I am having difficulty. How do I access this list box?
I have tried:
public class DeckManagement: Form
and
public class DeckManagement: WarGame
|
|
|
|
|
Your code seems totally irrelevant to the problem at hand.
Nathan Revka wrote: but I am having difficulty
Does it not compile, or do you get a runtime error? I would guess you need to make WarGame a public inner class of Form1, but that is terrible design - you should have WarGame as a full class in its own right, in WarGame.cs.
Cheers,
Vikram. (Proud to have finally cracked a CCC!) Recent activities:
TV series: Friends, season 10
Books: Fooled by Randomness, by Nassim Nicholas Taleb. Carpe Diem.
|
|
|
|
|
It is probably a better idea to expose a public method or property in your Form1 class that you would execute from your satellite class.
For example, if you needed to access the listbox from a different class so you can retrieve the selected index, you might within your Form1 class expose a public method:
public partial class Form1
{
...
public int GetListSelectedIndex()
{
return listBox1.SelectedIndex;
}
...
}
|
|
|
|
|
Hi guys
Can anyone show me where there are any tutorials on making a basic server in C#. Something that will run on port X and other computers in that network will be able to contact to the server and the server send a response (plain text).
Thanks guys
|
|
|
|
|
|
Cool
Thanks for the links.
|
|
|
|
|
i m creating a bot for a browser game, i really in the start yet
so, i enter the page and i need to pass password and username etc
so i found that code in vb but i cant find the translation
i so thing i missing a assembly case its really simple
...
wb.documents.all("username").value = "qwerty1"
wb.documents.all("password").value = "qwerty2"
wb.documents.all("submit").value = click
...
thanks
wb is WebBrowser object
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
There are online converters that will do this. If you can't do it yourself, then perhaps you need to understand C# better instead of just copying and pasting code from the web ?
Replace the () with [] and put a ; at the end. That is all.
Except I am not sure that the last line will work, in VB or C#, unless click is a variable that's already defined.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
() or [] doesn´t matter, like i said before i am missing a assembly, i cant find it
i used value propriety before, to pass values to db for exemple
... sql_cmd.Parameters.Add("@my_season", SqlDbType.Int).Value = season; ...
but i cant find the assembly to value propriety this case in order to pass values to site login page
nelsonpaixao@yahoo.com.br
trying to help & get help
modified on Wednesday, July 29, 2009 7:20 PM
|
|
|
|
|
In this code, I want to set the color of the progress bar to one thing, wait, then set it to something else, each time timer1 ticks. It doesn't work. Any suggestions?
private void timer1_Tick(object sender, EventArgs e)
{
progressBar2.ForeColor = Color.Firebrick;
Thread.Sleep(50);
progressBar2.ForeColor = Color.Black;
}
|
|
|
|
|
Firstly, at 50ms you won't see anything.
Secondly, why don't you just keep the timer ticking and each time you just swap the colours.
Thirdly, Sleep on the UI thread is, no mater how short, not a good idea.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
You'll need a thread.
See here[^].
|
|
|
|
|
Rather than using Timer and Thread.Sleep() , I will suggest you to use, Background worker to do this. Which will manage both the UI and background process.
|
|
|
|
|
Hi,
I also have sometimes the problem that I want to "wait" for a short time (some 10 or 100 milliseconds) and so far I helped myself with Timer and Thread.Sleep... (shame on me but I didn´t know better)
Is there any article or a short example how to do this correctly with Background worker?
Thanks
Thomas
|
|
|
|
|
ThomasManz wrote: Is there any article or a short example how to do this correctly with Background worker?
Yes, Using background worker you can show the progess on UI and aswell as do the process on backgronud.
Here is one sample application.
Using the BackgroundWorker Component in .NET 2 applications
Hope this is Help to you
|
|
|
|
|
therealrustyspork wrote: private void timer1_Tick(object sender, EventArgs e)
{
progressBar2.ForeColor = Color.Firebrick;
Thread.Sleep(50);
progressBar2.ForeColor = Color.Black;
}
You shouldn't use Thread.Sleep in GUI thread, but if you really want to, you need to redraw the progress bar.
private void timer1_Tick(object sender, EventArgs e)
{
progressBar2.ForeColor = Color.Firebrick;
Application.DoEvents();
Thread.Sleep(50);
progressBar2.ForeColor = this.ForeColor;
}
Greetings - Jacek
|
|
|
|
|
My question is how to create this: for an existing object a new custom property?
"existing object"= an object control in general (ex: a textbox)
"new custom property"= by default this control "textbox" have this property:
textbox.Hide();
...and many other properties off course,but I snipe to this particular one, only.
In what way? Well, I want that a single button to have a custom property write by me, named "myHideShowProperty" that can do 2 things in one package, I mean that when I click once, "Show" that textbox ; and when I click one more time it "Hide" that textbox, then when I click once more it "Show" a textbox,and so on.
In the end, the code I imagine that it must look like this:
btn1.myHideShowProperty.show(textbox);<br />
btn1.myHideShowProperty.hide(textbox);
The idea behind all of this is how to write a customized property for an existing object control.
And of course a solution for my problem, if there is one.
though I must mention that I have made a variant and it works:
private void button1_Click(object sender, EventArgs e)<br />
{<br />
button1.Hide();<br />
button3.Show();<br />
button3.Text = "second btn";<br />
}<br />
<br />
private void button3_Click(object sender, EventArgs e)<br />
{<br />
button3.Hide();<br />
button1.Show();<br />
button1.Text = "first btn";<br />
}<br />
|
|
|
|
|
The normal way is to derive a new class from the control
public class Foo : Button
but there is another way in VS2008 : Extension methods[^] which does exactly what you are asking for.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
The same btn click event who can switch between 3 strings like "Aa", "Bb","Cc"?
1 click pop up the first string, second click(same btn) pop up the second string, and the third click(same btn) the last string?
And after the third one it begin with the first string, second,etc.
|
|
|
|
|
Hello, I'm currently teaching myself asynchronous socket programing. Should mention I got the code here http://www.codeguru.com/csharp/csharp/cs_network/sockets/article.php/c8781#Client6[^] and have been editing it and improving it.
Anyway the problem I'm having is after I kick someone for trying to use a name someone else has or they change their name while they are connected to a name someone else has, a rouge string "\0" is sent seemingly from the client, even though when I kick the client and the socket is closed he still manages to send it. I know it happens after I send a message to the client.
The reason that this is kinda of a problem is because I'm using substring and of course the string is just too short.
I know I can just use an if sentence that makes it ignore everything that is fewer than x characters but I really want to know where this rouge text string is coming from.
Can someone help me?
Sorry about not posting the code but it is very long and I can't really pinpoint where the error is.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Tumminn wrote: The reason that this is kinda of a problem is because I'm using substring and of course the string is just too short.
So, before getting the substring, make sure the input is long enough. It is the programmer's job to validate the input and to manage whatever happens. It may well be that the client app is sending the string when it disconnects, but why are you even trying to process a message from a client session that yoou have rejected?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
That is not my intention it just happens, I just want to know the reason for why I get this data. It only happens if I send a message to him then I get the string "\0" back for no reason.
Also I know about validating bit but I'm just curious why it happens.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Is the client your own code too? Welcome to the wonderfull world of debug!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Okay fixed the part about the changing names while server is live but still have the problem of it trying to receive data from a socket that is closed, which it shouldn't do but does anyway just to spite me.
This is the code to closing the socket (Server Side)
string msg = "Name Taken";
byte[] byData = System.Text.Encoding.Default.GetBytes(msg);
socketData.m_currentSocket.Send(byData);
socketData.m_currentSocket.Close();
m_workerSocketList.Remove(socketData.m_currentSocket);
m_clientCount--;
This is the code where is error happens (Server Side):
try
{
if (pfnWorkerCallBack == null)
{
pfnWorkerCallBack = new AsyncCallback(OnDataReceived);
}
SocketPacket theSocPkt = new SocketPacket(soc, clientNumber);
soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt);
}
catch (Exception se)
{
MessageBox.Show(se.Message);
}
And last bit the client does when it is kicked:
if (m_clientSocket != null)
{
m_clientSocket.Close();
m_clientSocket = null;
UpdateControls(false);
}
Any ideas?
modified 27-Feb-21 21:01pm.
|
|
|
|
|
I am just guessing here. Is the listener fully disconnected from the serve before or after sneding the FOAD message to the client? Try either removing the listener side of things BEFORE the disconnect message or WAITING for a disconnect from the client. I prefer teh first of the two.
If you have disconnect from the server end, then there is no way that the client can send you any EOS messages which is what I think you are getting.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|