|
You will need to use a richtextbox to display formatted text.
For an example, see here.
Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
<code>//executed in the main class
int testint = 0;
NewClass.test(this);
//NewClass
public void test(object sender)
{
PropertyInfo[] properties = sender.GetType().GetProperties();
foreach (PropertyInfo prop in properties)
{
MessageBox.Show(prop.Name);
}
}</code>
Im trying to write a reusable class for updating a ToolStripStatusLabel on multiple forms, Im using the code above which seems to work when i manually create a new class instance but when i try to use the sender properties.Length comes up as 0.
Im trying to get all the properties of the mainclass like testint
|
|
|
|
|
Cwhen this is not working which object you are passing other that your custom class.Is a label class
|
|
|
|
|
Can you try,
sender.GetType().GetProperties(BindingFlags.Instance)
Let us know if it works.
|
|
|
|
|
<pre>MessageBox.Show(properties.Length.ToString());
foreach (PropertyInfo prop in properties)
{
MessageBox.Show(prop.Name);
}</pre>
The above still comes up as 0 so the foreach isnt run.
sender.GetType().Name returns the class name though.
|
|
|
|
|
Could you please post the Meta details of the Class that Contains the ToolStripStatusLabel Property
|
|
|
|
|
|
GetProperties(BindingFlags.NonPublic | BindingFlags.Static) still gives a length of 0
heres the class im launching the the function from if it helps.
<code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.IO;
using System.Web;
namespace TestAplication
{
class MainClass
{
string URL;
string Name;
int Count = 0;
int SectionNumber = 0;
public int Delay = 0;
Taskbar TaskbarClass = new Taskbar();
public void GetSections(Form this, string CurrentmURL, string CurrentFormName)
{
TaskbarClass.test(this);</code>
|
|
|
|
|
Hello,
i sometimes get the "Safe handle has been closed" exception when i CLOSE my application (in debug mode). When i run it from the exe and try to close the app i simple get the "program has stopped working" error. I use a com port to communicate with an external device.
I hear it has something to do with a .net bug but is there anything i can do in the Form_closing event perhaps or somewhere else to stop it from showing when i close my program. How could i handle that exception?
Heres the stack trace:
System.ObjectDisposedException was unhandled
Message="Safe handle has been closed"
Source="mscorlib"
ObjectName=""
StackTrace:
at Microsoft.Win32.Win32Native.SetEvent(SafeWaitHandle handle)
at System.Threading.EventWaitHandle.Set()
at System.IO.Ports.SerialStream.AsyncFSCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
InnerException:
My idea was the following: (to make sure that the communication thread does not send anything else when user wants to exit)
Form_Closing event
{
signal_comm_thread
loop while(getSignal_from_comm_thread)
}
Comm_thread
{
if(signal_received)
signal_Form_Closing event
break;
}
But the program wont close at all this way Tried to use ManualResetEvents, public static variables for the signaling but nothing helps. Only way the program closes is if i add a "MessageBox.Show" in Form_Closing event after signaling comm_thread. How can that help?
TY
|
|
|
|
|
I've seen similar things happens when attempting to close a serial port read thread at form close.
What I do now is allow the reader thread to close the port and wait in the UI thread until the reader thread has exited. Like this:
private void ReadWriteThreadProc() {
continueLooping = 1;
try {
while (continueLooping != 0) {
try {
received = com.Read(buffer, 0, buffer.Length);
} catch (TimeoutException) {
}
}
} finally {
com.Close();
}
}
public void CloseCom() {
Interlocked.Exchange(ref continueLooping, 0);
ReadWriteThread.Join();
}
The timeout is rather crucial as it ensures that the exit condition is polled.
Alan.
|
|
|
|
|
Are you using a serial port, or a USB-to-serial converter? The SerialPort object in .Net does not behave well at all if a port is open on a USB-to-serial converter that is unplugged. I don't know any good libraries, but I'm sure they're out there. For my application, I coded a silly little helper application which acts as a bridge between a TCP socket and a .net SerialPort object; if the SerialPort object dies, the helper application quits without jinxing the main app.
|
|
|
|
|
Hello,
I am a experienced C# developer and I have good knowledges about security and viruss.
I started this project a week ago, i finished some parts like scanner that read the file Hex and compare some parts to our ScannerDatabase.
What i need is some one to help in some things, like getting Trojan keys in the registry after detecting it, and also i need a security expert so he can show me how does trojan hide in other processes like Internet Explorer.
Tanck you, and i am waiting for your replies .
|
|
|
|
|
|
how can i open an exe file in a C# window?
i see an example in other site which open all open exe files in diffrent tabs.
but i want open my exe file in a panel ... how can i do this?
|
|
|
|
|
MarziehA wrote: how can i open an exe file in a C# window?
Start the executable, grab it's mainwindow, and use the SetParent -API.
MarziehA wrote: how can i do this?
This article[^] might help
I are Troll
|
|
|
|
|
I am writing a mobile device program for my university coursework but I am coming up against a few problems or limitations, I am not sure which, the two problems which I am finding is that I do not have some functionality which I normally have when writing for normal windows forms. The two problems I have is when I try and assign an Enum to a combo box,
Private Enum X
//Set of enums
End Enum
ComboBox1.DataSource = Enum.GetValues(GetType(x))
I am finding that I am not able to uses the "GetValues" or "GetTypes" of the enum functionality, which means that I can’t populate the combo box correctly. This is also found when the ImageConverter function which exists for normal windows form but doesn't exists when writing for the mobile framework.
Any help would be greatly appreciated.
|
|
|
|
|
It is annoying but that is the limitations of the compact framework - Missing properties and methods so you have to be more creative!
How about using a list as the source or failing that a generic routine to populate a combo box.
Try posting in the Mobile forum. They may have more for you.
Regards
The FoZ
|
|
|
|
|
I've been able to do it by using AddRange
Array arr = System.Enum.GetValues(typeof(MyEnum));
object[] oArr = new object[arr.length];
arr.CopyTo(oArr, 0);
combobox1.Items.AddRange(arr);
|
|
|
|
|
I am creating a snake game on the console (c#)(it is a school assignment and it has to be on console) but I’m struggling with the change of direction and this is because I can’t figure out how to use an eventhandler with keydown properly in console.
I’ve put together some mock up code below which more or less explains what I try to accomplish
I have tried several things but it is tricky to do on the console.
Any hints, suggestions would be greatly appreciated.
void KeyDown(object sender, EventArgs e)
{
if(e.thepressedkey == Right.Arrow)
method_a()
if(e.thepressedkey == Left.Arrow)
method_b()
}
void a()
{
while(something)
{
snake.moveright();
thread.sleep(500);
}
}
void b()
{
while(something)
{
snake.moveleft ();
thread.sleep(500);
}
}
|
|
|
|
|
You would need something along the lines of:
bool GameIsOn = true;
while (GameIsOn)
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey(true);
switch (key.Key)
{
case ConsoleKey.LeftArrow:
{
}
case ConsoleKey.RightArrow:
{
}
case ConsoleKey.UpArrow:
{
}
case ConsoleKey.DownArrow:
{
}
case ConsoleKey.Escape:
{
GameIsOn = false;
}
default:
{ }
}
}
}
If the post was helpful, please vote, eh!
Current activities:
Book: Devils by Fyodor Dostoyevsky
Project: Hospital Automation, final stage
Learning: Image analysis, LINQ
Now and forever, defiant to the end.
What is Multiple Sclerosis[ ^]?
|
|
|
|
|
Hi thanks!
I have actually tried that and that is almost what a want, however I'd like it to tick.
With this method you have have to press once for each step. I would like to start a loop of steps that loops until another directional key is pressed.
Any more thoughts?
|
|
|
|
|
Pffft!
You got me interested in writing the game myself now!
I'll probably post it as an article in a week or so.
But the way I'd do it is as follows:
void RunGame()
{
while (GameIsOn)
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey(true);
switch (key.Key)
{
case ConsoleKey.LeftArrow:
CharacterDirection = Direction.Left;
break;
case ConsoleKey.RightArrow:
CharacterDirection = Direction.Right;
break;
case ConsoleKey.UpArrow:
CharacterDirection = Direction.Up;
break;
case ConsoleKey.DownArrow:
CharacterDirection = Direction.Down;
break;
case ConsoleKey.Escape:
GameIsOn = false;
break;
default:
break;
}
#endregion
}
AdvanceStep();
CheckCollision();
Thread.Sleep(100);
}
}
Now in the AdvanceStep() method you're going to have calculate the new position of the cursor and Console.Write() the new character placeholder. This will "tick" in the sense that you will see the character move in whatever direction you first choose, ten steps in 1 second. You can make that faster or slower based on the number of milliseconds you let that thread sleep.
There are things that you have to bear in mind. The Character's initial position [ (0,0) vs centre point ] the character's initial direction and so on. If for example you set the initial position at (0,0) and the initial direction is Right, then the character will move to the right (x-axis change only) until a button is pressed that will alter the direction.
If there are many attributes that you would like to add to your character, such as the length of the tail (we are talking about a snake-clone, right?), and also a history of the turns that were made (so that the tail will also turn at the correct locations) you might want to break into a class and if the list of positions can be lengthy (as can easily happen on a "big screen" with an expert player) then you might want to break that into its own vector class list.
If you have anymore questions, post some code as well, and we'll see how we can help you with where you are stuck
If the post was helpful, please vote, eh!
Current activities:
Book: Devils by Fyodor Dostoyevsky
Project: Hospital Automation, final stage
Learning: Image analysis, LINQ
Now and forever, defiant to the end.
What is Multiple Sclerosis[ ^]?
|
|
|
|
|
Very nice thanks alot, yes I have solved most problems with the tail, borders food etc.
Thanks for spending the time on it!!
|
|
|
|
|
Glad to have helped
If you have anymore questions, we, and especially I, will be glad to help.
Check back in a week or so and see if I posted the article by then, then you can compare notes
Best of luck with your assignment.
If the post was helpful, please vote, eh!
Current activities:
Book: Devils by Fyodor Dostoyevsky
Project: Hospital Automation, final stage
Learning: Image analysis, LINQ
Now and forever, defiant to the end.
What is Multiple Sclerosis[ ^]?
|
|
|
|
|
Hi everyone.
This is probably something I should be able to figure out by myself, but I'm not having much luck so I figured I'd ask.
The issue: I'm translating a system from java to C# and they use a java framework[^] that I'd really like to use, since it takes care of the most complex parts of the system, which I would otherwise have to implement myself. I have the source code of this framework.
I know there are several possibilities for using java libraries in C# (although I'm not familiar with any of them, so I'd appreciate suggestions). So far I've thought of using IKVM.NET[^] to generate a .dll, but I'm not sure what to do next, because in java in order to run the framework with your code you're supposed to use the option -javaagent[^] by adding
-javaagent:bin/deuceAgent.jar (where deuceAgent is the framework) to your java command line. I don't know what the equivalent in C# would be once I have my .dll, or whether there's an equivalent at all.
Any help? Thanks so much.
|
|
|
|