|
Firs tof all, MessageBox.Show is the worst way to debug an application. Set a breakpoint on the line you want and in Visual Studio hit F5 while doing a debug build. That's real debugging and can yield far more valuable data than MessageBox.Show .
Define drawGraph like so (and please following .NET naming guideilnes when developing, which is documented in the .NET Framework SDK):
static readonly Pen BlackPen = new Pen(Color.Black, 1);
private void DrawGraph(Graphics g)
{
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (graphEnabled) DrawGraph(e.Graphics);
}
private void button1_Click(object sender, EventArgs e)
{
graphEnabled = true;
Refresh();
} I'm assuming here that button1 works as an enabler. When you call Refresh the client area is invalidated and redrawn immediately, meaning that OnPaint gets called. As long as graphEnabled is true in this example, any invalidated of your control (i.e., when a portion is hidden) will be redrawn with the graph.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
hi, sorry for the late reply. i took quite some time to draw my graph
1)i used your method and i managed to get what i want. however, i'm still not able to draw it into the picture box. my drawing is still drawn onto the form
2)how do i remove flickering? should i do it in drawgraph(Graphics g) or in protected override void OnPaint(PaintEventArgs e)
i've tried this but didn't work out:
this.SetStyle( <br />
<br />
ControlStyles.AllPaintingInWmPaint | <br />
<br />
ControlStyles.UserPaint | <br />
<br />
ControlStyles.DoubleBuffer,true);
Thanks.
Chris
|
|
|
|
|
Double-buffering won't solve all your problems. You need to honor the PaintEventArgs.ClipRectangle and draw only what needs to be drawn. You can also improve performance if you cache pens, brushes, and other static and semi-statis data (i.e., data that doesn't change each time you draw). If you're doing a lot of calculations and creating a lot of objects while painting, you will notice flicker.
I would suggest that - in situations like this - you take a look at the OnPaint override for the PictureBox to determine how it's currently working in order to override it the way you want. You can use ildasm.exe (from the .NET Framework SDK) to disassemble the assembly (if you know IL), or something like .NET Reflector to decompile (i.e., to source form) the source. Overriding the painting routines should work, but you must override painting for the PictureBox (not the containing control like a Form ) and you must first call base.OnPaint so that the PictureBox 's painting code doesn't paint over your drawing (last "write" wins).
You should also consider just dropping the PictureBox and painting an image yourself. The Graphics objects makes this easy. Just override OnPaint in a derivative Control class, paint the image, then paint over it all from within OnPaint (or methods it may call similar to what you're doing now).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I'm trying to reword the question I asked below in more general terms.
From a class classSecond how do you check if an object Obj_classFirst of classFirst has been created?
Also, how do you access and modify its value?
|
|
|
|
|
NietzscheDisciple wrote:
From a class classSecond how do you check if an object Obj_classFirst of classFirst has been created?
I guess if it has not been created, it will hold it's default value, which should be set to null. The real problem with this question is that it cannot be answered without knowing the relationship between the two classes.
NietzscheDisciple wrote:
Also, how do you access and modify its value?
If there is no interface so that one is a member of the other, or some other mechanism is provided through methods that both can see, the answer is that they can't.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Christian, thanks for the reply.
In my main form's class, I have an object of the DirectSound SecondaryBuffer class. It is declared as follows:
public SecondaryBuffer SecBuff = null;
and is initialized later in the code as follows:
SecBuff = new SecondaryBuffer(FileName, ApplicationDevice);
The above code belongs in the class "MainForm" that is declared as
public class MainForm : System.Windows.Forms.Form
Now, I have a separate Control,
public class ctlVolume: System.Windows.Forms.UserControl
All I have in this Control is a trackbar, tbVol. I want the volume of SecBuff to change when the trackbar value changes. This is accomplished by calling the Volume method on this object.
How do I access the object SecBuff which is in the class MainForm? How do I use interfaces to do it?
Thanks!
|
|
|
|
|
Maybe I'm missing something here, but it seems that you're trying to obtain an event from your user control that contains the trackbar. I don't really know why you need the separate UserControl, since you could just place the trackbar on the form, but if you have to do that, you'll need to declare a public event on the UserControl, then create an event handler in your form. In the user control, you would handle the value changed event (whatever that is) from the track bar, and raise the event.
The .NET documentation indicates a pretty straightforward design pattern for this. Assuming your event is ValueChanged you typically declare a method:
private void OnValueChanged()
{
if( ValueChanged != null ) ValueChanged(this, EventArgs.Empty);
}
In the event handler for the trackbar event, call this method.
You'll also need to expose a public property that tells you where the progress bar is, so that in your form, when you respond to the event you can read the value and pass it to your SecBuff.
All that said, really, it would be much easier just to site the track bar on the form and respond to its value changed event by passing the current track bar position into the SecBuff.
Another approach you could take would be to pass the SecBuff object into your user control as a property, then respond to the value changed event on the track bar by setting the corresponding value on the SecBuff object.
Tom Clement
Apptero, Inc.
www.apptero.com
articles[^]
|
|
|
|
|
Tom, thanks for the advice.
The volume control is just an example. I actually need to perform some DSP functions on the audio data. I have five controls for five DSP functions.
I'm trying to first establish communication between these two classes.
I'll try what you suggested and see if I can get it to work.
Thanks!
|
|
|
|
|
Tom, could you please clarify which method goes on the main form and which goes in the Control?
Thanks!
|
|
|
|
|
Hmmmm.... first, you need a plan. Here's the situation as I see it:
--- OPTION 1 ---
1. You have a UserControl that sits on your form.
2. You want to be notified when something changes on your UserControl.
3. You want to be able to read a property on the user control that tells you the slider bar position.
So, first you declare the event on the UserControl, like this:
public event EventHandler SomethingChanged;
Then you write the standard private method for raising the event like this:
private void OnSomethingChanged()
{
if( SomethingChanged != null ) SomethingChanged(this, EventArgs.Empty);
}
Then you call OnSomethingChanged() when something changes, like this:
private void tbVol_Changed(object sender, System.EventArgs e)
{
OnSomethingChanged();
}
You also want to expose the current value of the tbVol control as a property, so you probably do something like this:
public int TrackValue { get { return tbVol.Value; } }
---------
Now, in your form, you want to respond to this event on your user control. So you want to create an event handler for the SomethingChangedEvent. If you're using the IDE, you can go the the properties window, events tab, and double click in the value area for SomethingChanged. That will generate the event handler which you can use to set the value of your SecBuff object.
private void ctlVolume_SomethingChanged(object sender, System.EventArgs e)
{
SecBuff.Volume = ctlVolume.TrackValue;
}
----------------------------------------------------
---- OPTION 2 -----
If that doesn't work for you, you could add the following code to your ctlVolume control:
private SecondaryBuffer m_buff = null;
public void SetSecondaryBuffer(SecondaryBuffer buff)
{
m_buff = buff;
}
You could call this right after:
SecBuff = new SecondaryBuffer(FileName, ApplicationDevice);
like this:
ctlVolumme.SetSecondaryBuffer(SecBuff);
Then you could write the event handler for tbVol Changed event like this:
private void tbVol_Changed(object sender, System.EventArgs e)
{
if( m_buff != null )
m_buff.Volume = tbVol.Value;
}
I hope this gets you started. Truthfully, it's pretty much beginner stuff.
Tom Clement
Apptero, Inc.
www.apptero.com
articles[^]
|
|
|
|
|
This is a newbie question, but I would be grateful if someone could clear this concept for me.
Suppose I have:
1. A class cMainForm that has a DirectSound object, SecBuffer
2. A control for this class, cControl , that has a trackbar which controls the volume of the DirectSound buffer.
How do I get the code in the cControl class to verify and recognize that the object <secbuffer> has been created, and how do I use it?
My app requires that the code be written in separate classes, because different controls will all access the same SecBuffer object.
Thanks for your help.
|
|
|
|
|
Are cControl also on cMainForm. If so you only have to write the code to bind them together. If not, you will have to make public properties, methods and events on cMainForm that expose the features that you would like. If the cControl class only wants to detect if the object SecBuffer is created you can use a read-only property.
|
|
|
|
|
I am trying to retrieve the password age from Active Directory using the classes in System.DirectoryServices. how ever when I get that property it is returning a COM object. What do I need to do with that to get the password age out?
Cheers,
Andy.
|
|
|
|
|
"COM object" is not specific. Please tell us what type the debugger reports. You should also set a breakpoint after getting the property and examine the data in the object to determine what is exposed. You may have to declare COM interfaces to extract the data, but without knowing more it's difficult to help you.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Heath Stewart wrote:
"COM object" is not specific. Please tell us what type the debugger reports.
That IS what the debugger reports. To be exact it is a System.__ComObject
If I drop it into the watch window and expand it out it still gives me no new inforomation.
Heath Stewart wrote:
You may have to declare COM interfaces to extract the data
Maybe that is what I need to know. What COM interfaces do I have to declare? I have searched all over the place, MSDN, Google, Google Groups and this seems to be something that is just swept under the carpet. No one either knows or wants to know. There are a few VBScripts out there, but that does not really help me. Or perhaps my search terms are not quite right. I've searched on various combinations of: LDAP DirectoryServices DirectoryEntry PasswordAge Active Directory .NET C#
What I am trying to do is authenticate a user as they log in to my system (as described in How To Use Forms Authentication with Active Directory http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT02.asp[^]) and then warn them if their password is about to expire. Perhaps I am not looking at this from the right angle.
If it helps I wrote a little test app to try some things out. Perhaps I'm doing something wrong here:
static void Main(string[] args)
{
string thePath = "LDAP://company.co.uk/DC=company,DC=co,DC=uk";
string domainAndUsername = domain + @"\" + username;
Console.Write("Enter Password:");
string password = Console.ReadLine();
for(int i=0;i<300;i++)
Console.WriteLine();
DirectoryEntry entry = new DirectoryEntry( thePath,
domainAndUsername, password);
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if(null == result)
{
return;
}
thePath = result.Path;
string theFilterAttribute = (string)result.Properties["cn"][0];
PropertyCollection coll = entry.Properties;
Console.Write("Number of properties: {0}", coll.Count);
foreach (string name in coll.PropertyNames)
{
PropertyValueCollection pvc = coll[name];
object val = pvc.Value;
if ((name == "minPwdAge") || (name == "maxPwdAge"))
Debugger.Break();
Console.WriteLine("{0}: {1}", name, val);
}
Console.ReadLine();
}
|
|
|
|
|
Take a look at WinNT Custom User Properties[^]. PasswordAge is a Time type, but I'm not sure why that would appear as __ComObject (which, btw, is more helpful to me than just "COM object"). You should dig through the related documentation from above about the Time type. I would expect this to be a VARIANT . You could try Marshal.GetNativeVariantForObject which would give you an IntPtr which you could then use (more than likely, but there are numerous ways) Marshal.PtrToStructure .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
hi there,
is it possible to add a custom property to an object during runtime?
i have a string that represents the property name and a type that represents the property type. i have to do that at runtime because both parameter values are not available before. would that be possible with emit? or do i need to create the whole clase with emit then?
regards, andré
|
|
|
|
|
Yes and no. You can't actually add a property at runtime to a class, but there are two options. You can compile a new class that's a derivative of the one you'd like to modify (and rely on polymorphism) using Reflection Emit or CodeDom. Read Emitting Dynamic Assemblies[^].
Another way is to create the illusion that you've added properties, but this only works for component model clients (like TypeConverter s, TypeDescriptor , and the PropertyGrid by implementing ICustomTypeDescriptor . You can read about it[^] in the .NET Framework SDK.
Basically, you override GetProperties like so:
public PropertyDescriptorCollection GetProperties()
{
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(this, true);
return props;
}
You would extend PropertyDescriptor (you wouldn't have to, but I often find it easier) to support creatable properties at runtime.
Again, though, this only works for clients of the component model that actually use the ICustomTypeDescriptor implementation. If you just tried to access such a property using early binding like myObject.MyNewProp then it would fail because that property isn't actually defined on the class.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
|
actually that's what i'm doing. but infragistics webgrid columns seem to accept just real-properties...
regards, andré
|
|
|
|
|
I need a help.
if i only click the master data grid link column, it has to pass that column value & display details in the grid below the master gird in the same asp.net form.( both master and details has to display)
i set the target as self,but it displays only the details grid.
help will be appriciated.
thanks
|
|
|
|
|
Your question belongs in the ASP.NET forum.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
How can i arrange data in an xml file alphabetically?
<?xml version="1.0" ?>
<names>
<name>>Matt Daimon</name>
<name>Kate Winsilet</name>
<name>Martha Stewarts</name>
<name>Will Smith</name>
<name>Britiny Spears</name>
<name>Jenifer Lopez</name>
<name>Jenifer Aniston</name>
</Names>
<pre>
Plz any sort of help will be gr8!
|
|
|
|
|
That's a rather ambiqous question. Do you want to have it sorted in the file and rewritten? You can do that with an XSL Transform that looks like so:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" version="1.0" standalone="yes"/>
<xsl:template match="Names">
<xsl:element name="Names">
<xsl:apply-templates select="Name">
<xsl:sort select="."/>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="Name">
<xsl:element name="Name">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet> To transform the XML, you can do something simple like this:
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
class Test
{
static void Main(string[] args)
{
if (args.Length != 2) Environment.Exit(1);
Transform(args[0], args[1]);
}
static void Transform(string xml, string xsl)
{
XmlDocument doc = new XmlDocument();
doc.Load(xml);
XslTransform tran = new XslTransform();
tran.Load(xsl);
tran.Transform(doc, null, Console.Out, null);
}
} If you just want to read the data in and sort it, you can do something like this:
using System;
using System.Collections;
using System.IO;
using System.Xml;
class Test
{
static void Main(string[] args)
{
if (args.Length != 1) Environment.Exit(1);
Sort(args[0]);
}
static void Sort(string file)
{
XmlDocument doc = new XmlDocument();
doc.Load(file);
XmlNodeList nodes = doc.DocumentElement.SelectNodes("/Names/Name");
string[] names = new string[nodes.Count];
int i=0;
foreach (XmlNode node in nodes)
names[i++] = node.InnerText;
Array.Sort(names, Comparer.Default);
foreach (string name in names)
Console.WriteLine(name);
}
} There's practically an infinite amount of ways you can sort this data - it just depends on your needs.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
How would I go about searching for a specific file on my local drives at runtime.
Something like this (psuedo code)
if (searchForFileMethod('myFile.dat')
// get the path to the file
else
// inform the user that file is not found
Any hints or tips would be appreciated.
Thanks,
Einar
|
|
|
|
|