|
Hi Lao.
Thank you for you help.
But, the thread method is the method that read the comm. port, so can I pass a parameter to it?, a parameter like TextBox tb?.
That method is in another class, no in the class that holds the textbox, and should I pass every control as parameter that I want to write, (with data from the comm port)?.
Thank you again for your time.
Demian.
|
|
|
|
|
The code works fine.
But I must pass a textbox reference to the class constructor. And this is a very particular case, 'cause I don't know how many controls I will have, to show the data that the thread read from the comm port.
Thank you Judah.
Demian.
|
|
|
|
|
This is only if your thread method is in a different class. More than likely, there's no need to do that. In both Judah's and my examples, we assumed the method that will be invoked in another thread was part of the same class, so it already has a reference to the TextBox . This is preferred unless you have some good reason for changing it. If you do, then create a new instance of another class - passing the TextBox reference into the constructor - and start a thread on a method of that class. This is unnecessary, though, because you're creating another class just to run a method in another thread? Why go to the trouble if you don't have to.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi!
Well, I have a class hierarchy, and theses classes must keep a communication "alive" with a devices pluged in the comm port. The device, if it has no heceived a command stop the communication.
That is the trouble, the thread method is a method deep int the hierarchy.
Thank you for your time.
Demian.
|
|
|
|
|
Like I said, then, either pass the TextBox reference into the class's constructor or set a property before you start the thread on a method of that class.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi.
Yes, that works, but there's no relation between the classes hierarchy and a control as reference in a constructor or in a property.
Theses are communication protocol classes, it's so weird to find a control reference in their definitions. I loss the essence of the class hierarchy just putting a textbox in the definitions.
That's the problem.
Thank you very much for your feedback.
Demian.
|
|
|
|
|
Hello masters,
I have done a simple application in C# where I simply create a new UserControl derived class that draws a diagonal a red line on a blue background.
I have used some techniques used in C++ to avoid flickering, but when I resize my dialog box that contains my control, the drawing awfuly flickers.
How can I avoid flickering drawings?
I do the following thing:
<br />
internal sealed class Tetrion : UserControl<br />
{<br />
private GameBoard m_gameBoard=new GameBoard();<br />
<br />
internal Tetrion()<br />
{<br />
Debug.WriteLine("Tetrion.Tetrion");<br />
SetStyle(ControlStyles.DoubleBuffer, true);<br />
}<br />
<br />
public void Draw(Object sender, PaintEventArgs e)<br />
{<br />
Debug.WriteLine("Tetrion.OnPaint");<br />
m_gameBoard.Draw(e.Graphics, ClientRectangle);<br />
}<br />
<br />
protected override void OnResize(EventArgs e)<br />
{<br />
base.OnResize(e);<br />
Invalidate();<br />
}<br />
}<br />
I have registered the Draw event in the MainForm's constructor class like this:
<br />
m_tetrion.Paint+=new PaintEventHandler(m_tetrion.Draw);<br />
and, at last, the Draw method of the GameBoard class looks like this:
<br />
public void Draw(Graphics graphics, Rectangle rect)<br />
{<br />
Debug.WriteLine("GameBoard.Draw");<br />
<br />
Bitmap bmp=new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);<br />
Graphics memGraphics=Graphics.FromImage(bmp);<br />
Pen pen=new Pen(Color.Red);<br />
<br />
SolidBrush brush=new SolidBrush(SystemColors.Control);<br />
memGraphics.FillRectangle(brush, rect);<br />
<br />
memGraphics.DrawLine(pen, rect.X, rect.Y, rect.Width, rect.Height);<br />
<br />
graphics.DrawImage(bmp, rect);<br />
}<br />
I think everything looks fine to me in the code, but it still flickering...
Please, help!
Thanks!!!
|
|
|
|
|
According to the documentation for ControlStyles.DoubleBuffer , you must also set ControlStyles.UserPaint and the ControlStyles.AllPaintingInWmPaint to true also for double buffering to work properly. For example
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
If you're going to be doing ~all~ the painting, don't use a UserControl. Instead you'll want to write a custom control: just create a class an inherit directly from System.Windows.Forms.Control class. Visual Studio has a template for this, Project->Add Class->Custom control.
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
Thanks a lot Judah!!!
It works great that way. it does not flickers anymore!
|
|
|
|
|
In addition to what Judah said, using Debug.WriteLine in drawing code is NOT recommended. The TraceListener s (both Debug and Trace use them, which are compiled to code if the DEBUG and/or TRACE pre-proc defs are defined at compile time) are very slow. When you debug this application, it gets even slower since the DefaultTraceListener uses the native OutputDebugString which VS.NET catches and displays in your output window - this is a blocking call (i.e., your drawing code is foregone until that process described above is complete).
If all you had was the Debug.WriteLine and did a default Release compile, it wouldn't be included, but there's really no reason to trace this call anyway. It either works or it doesn't, and this will only slow it down. If you're painting your control, you'll notice if it works and you don't need a trace statement for that.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
Thanks for the answers. If I included traces in the Drawing procedure, it's because I want to know if it does not call too many times. Then I see that when I resize my dialog box, the drawing function is called only once. But even in Release, it's still flicker with or without the trace calls.
|
|
|
|
|
I'm just sayin'...
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
After applying Judah's modification, when I have debug traces it slows down, but it does not flicker. In release, it runs smoothly C# is cool!
|
|
|
|
|
By the way,
In C#, I don't see any differences between these two drawing techniques (both are smooth):
- creating the image in a memory bitmap then display it once the bitmap is done,
- directly draw on the graphic's context (DC) without using a memory bitmap
Both are smooth. I guess it's because of the SetStyle call.. right?
In MFC/Win32, when you draw directly on the DC, it flickers, that's why you need to create the image in memory, and once done, you display it. in C#, wether or not the bitmap is built in memory, there is no flickering
Best regards.
|
|
|
|
|
bouli wrote:
I guess it's because of the SetStyle call.. right?
Most likely. If you specify the right flags for double-buffering, the OnDraw is probably called in a different thread (or buried deep in implementation) and once finished the image is drawn to the DC (or flipped). I haven't looked into it that deep.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
how can i encrypt the output of my program using the 128 bit encrypt algorithm?
|
|
|
|
|
System.Security.Cryptography implements a whole bunch of ways to encrypt look in the encryption part of this site: CP on Cryptograhpy
|
|
|
|
|
How to insert images from one window to different windows .for more info u can see the smilyes of outllok .
This is Jitendra
|
|
|
|
|
This can be done with a RichTextBox. There's a good article explaining this in more detail somewhere on this site, I suggest you do a search.
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
hi all =)
i'm looking on a way to retrieve the date time stamps that are stored in the cache index.dat of IE in order to know the time spend on each url.
if someone can help me
thx a lot
|
|
|
|
|
The cookie cache's index.dat file is weakly encrypted, this straight from the mouth of Microsoft. I'm betting the web cache's index.dat is too. They do that for a reason, so I won't suggest trying to reverse engineer it.
There is an "easier" way, though. Okay, it may not be easier if index.dat isn't encrypted, but it's 100% legal and more durable since Microsoft could change the format of index.dat at any time. Developers aren't supposed to be in it (and I honestly do recommend against this), so Microsoft has the right to change it whenever they want (for performance, size, whatever).
You'll have to declare the IUrlHistoryStg and IEnumSTATURL interfaces (with the proper GuidAttribute s), and define the STATURL structure. Then create a class that implements IUrlHistoryStg and is attributed with the GuidAttribute with the CLSID CLSID_CUrlHistoryStg , which is {3C374A40-BAE4-11CF-BF7D-00AA006946EE}. Also be sure to use the ComImportAttribute or else the CLR will create an instance of your object that uses empty definitions instead of the actual COM instance.
Create an instance of your IUrlHistoryStg implementation class, enum the URLs and get the STATURL struct for each, which gives you the various dates (although IE doesn't track how much time was spent on each site, so I'm not sure what you're talking about there). This will give you the last access time.
Of course, since all the URL history items are actually just .url shortcuts on the file system, you could always use simple IO to enumerate the files and check their last modification date. That should also work.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
If i have a xml document like this:
<?xml version="1.0" standalone="yes"?>
<sessions version="1.0">
<session name="Development">
<parameters>
<rootdirectory>n:\realsoftware</rootdirectory>
<validoslist>win32</validoslist>
<propathwin32>.,[rootdirectory]\usr\%username%,[rootdirectory]\fastforward\pvs100,[rootdirectory]\src,[rootdirectory],[rootdirectory]\start</propathwin32>
</parameters>
</session>
</sessions>
Now i want the text in propathwin32 in a textBox but i can't do it
I tried it like this:
XmlDocument xml = new XmlDocument();
xml.Load(@"c:\listbox.xml");
string test = xml.GetElementsByTagName("propathwin32").ToString();
and i tried it with InnerXml.
can anyone help me?
Thx in advance
|
|
|
|
|
Load the document and use the appropriate XPath expression:
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode node = doc.DocumentRoot.SelectSingleNode(
"/sessions/session/parameters/propathwin32");
if (node != null)
{
} Also, if you use a namespace to qualify your elements (or even attributes, but that's no typical), make sure you qualify them in code, too, by creating an XmlNamespaceManager using XmlDocument.NameTable as the argument to the constructor. Add your namespace and whatever prefix you want (the prefixes don't have to match - only the namespaces). To note, default namespaces (prefixes that equal "") don't work for some weird reason so you'll have to specify an actual prefix.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
you are using the wrong property.
use InnerText rather than InnerXml
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
how to use it in c# and functions inside it?????
|
|
|
|
|