|
LighthouseJ wrote: the first two classes trigger fine but C and D's are never used.
I believe you may need to make B 's ToString() virtual.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
I thought about that before and tried it but there was no difference in the outcome in runtime.
|
|
|
|
|
LighthouseJ wrote: The project is too complex
Here's a simple solution.. has the same class hierarchy as you described.. and it shows the .ToString() values. (I hope you're not confusing ListBox with ListView)
- Malhar
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
<br />
namespace Malhar.ControlGallery<br />
{<br />
public class Form3 : System.Windows.Forms.Form<br />
{<br />
private System.Windows.Forms.ListBox listBox1;<br />
private System.Windows.Forms.Button Load;<br />
private System.ComponentModel.Container components = null;<br />
<br />
public Form3()<br />
{<br />
InitializeComponent();<br />
<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if(components != null)<br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}<br />
<br />
#region Windows Form Designer generated code<br />
private void InitializeComponent()<br />
{<br />
this.listBox1 = new System.Windows.Forms.ListBox();<br />
this.Load = new System.Windows.Forms.Button();<br />
this.SuspendLayout();<br />
this.listBox1.Location = new System.Drawing.Point(8, 16);<br />
this.listBox1.Name = "listBox1";<br />
this.listBox1.Size = new System.Drawing.Size(176, 95);<br />
this.listBox1.TabIndex = 0;<br />
this.Load.Location = new System.Drawing.Point(192, 8);<br />
this.Load.Name = "Load";<br />
this.Load.TabIndex = 1;<br />
this.Load.Text = "button1";<br />
this.Load.Click += new System.EventHandler(this.button1_Click);<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.ClientSize = new System.Drawing.Size(292, 266);<br />
this.Controls.Add(this.Load);<br />
this.Controls.Add(this.listBox1);<br />
this.Name = "Form3";<br />
this.Text = "Form3";<br />
this.ResumeLayout(false);<br />
<br />
}<br />
#endregion<br />
<br />
private void button1_Click(object sender, System.EventArgs e)<br />
{<br />
listBox1.Items.Add(new A());<br />
listBox1.Items.Add(new B());<br />
listBox1.Items.Add(new C("John", 4));<br />
listBox1.Items.Add(new C("Lisa", 10));<br />
listBox1.Items.Add(new D());<br />
}<br />
<br />
class A<br />
{<br />
public A():base()<br />
{<br />
}<br />
public override string ToString()<br />
{<br />
return "Object of type A";<br />
}<br />
}<br />
class B:ArrayList<br />
{<br />
public B():base()<br />
{<br />
}<br />
public override string ToString()<br />
{<br />
return "Object of type B";<br />
}<br />
}<br />
class C:B<br />
{<br />
string someStr;<br />
object someVal;<br />
public C(string text, object value)<br />
{<br />
someStr = text;<br />
someVal = value;<br />
}<br />
public override string ToString()<br />
{<br />
return string.Format("Object of type C: {0}; {1}", (someStr==null?"-":someStr), (someVal==null?"-":someVal.ToString()));<br />
}<br />
}<br />
class D:B<br />
{<br />
public D()<br />
{<br />
}<br />
public override string ToString()<br />
{<br />
return "Object of type D";<br />
}<br />
}<br />
}<br />
}
|
|
|
|
|
Actually, I was wrong and it's a combobox, but class B contains the string and a custom class, and C has an int. My class structure and ToString() method definitions are basically the same thing, you say yours works so I don't know what's different to not work.
|
|
|
|
|
Hello,
In my Windows Form, I have almost 20 textboxes and editable controls. I was wondering is there any way i can apply Edit Menu (Cut, Copy, Paste, Select All) fetaures and MOUSE RIGTH CLICK MENU (CUT, COPY, PASTE, SELECT ALL) and SHORT CUT KEYs ( CTRL + C, CTRL + V, CTRL + X, CTRL + A) without writing code for each control seperately ? It is very boring and very hard to write code for each control, right ! So, I am pretty sure there must be an easy solution for that. So, would you please let me know if there is any solution to this kkind of boring task !!
thanks to all
Emran
|
|
|
|
|
You do realise you can apply the same event handler to every textbox on a form right? For example, the KeyDown event
private void MyKeyDownEventHandler(object sender, KeyEventArgs e)<br />
{<br />
}<br />
<br />
myTextBox1.KeyDown += new KeyDownEventHandler(MyKeyDownEventHandler);<br />
myTextBox2.KeyDown += new KeyDownEventHandler(MyKeyDownEventHandler);<br />
myTextBox3.KeyDown += new KeyDownEventHandler(MyKeyDownEventHandler);
|
|
|
|
|
Hi J4amieC,
Thanks for your reply.
Yes, i realize that i can use same handler, but you see, in that handler i will have to use a very big list of if else statement for every text box, right ?
like,
if(txtbox1.Focused)
txtbox1.Copy();
else if(txtBox2.Focused)
txtbox2.Copy();
............
.................
...............
ekse if(txtboxN.Focused)
txtBoxN.Copy();
and then I will have to write same if else for CUT(), PASTE, SELECTALL,... right ? and I thought it s a very hard way to maintain codes and there must be some simple method solution for this purpose as this task is essential for everyone for any kind of application and there must be some way available for this task.
thanks and regards
Emran
|
|
|
|
|
what is the best way to create a controll with my how drawing?
Can i use for it a bitmap at the place drawing it in GDI+?
(i ask this becouse i've tried to create a button using a panel then set as backgound an image loaded from the Hard disk, at the mouse action i get other images from an imagelist object, but i don't like this way futhermore on the on paint event i see this panel all black before to see the image)
|
|
|
|
|
Well if there is no image set, then just clear the control in the backgroundcolor you like, best use a property:
e.Graphics.Clear(BackgroundColor);
if (image != null) {
e.Graphics.Drawimage(...);
}
Greetings,
Ingo
------------------------------
An bug in a Microsoft Product? No! It's not a bug it's an undocumented feature!
|
|
|
|
|
Hi,
For example,
I am trying to know when I opened, say,'example.doc' word file or 'example.pdf' file.
I know msword or acrobat is running...
But how can we know which file was opened by msword or acrobat.
FileSytemWatcher looks like responding on only the events which changed file content.
Reading a file isn't an event reported by the watcher.
Process gave me module name but not the target file(doc or pdf file name).
Maybe I am missing some user32 functions.
But at this point, I don't know how to retrieve that information.
Many thanks in adance,
yjoo.
|
|
|
|
|
FileSytemWatcher is watching for changes. When you open a file, the OS puts a virtual lock on the file but does actually modify the file. But when a file is saved, the FSW will trigger the modify event.
- Malhar
|
|
|
|
|
Thanks for reply...
Yes,I know we can detect any changes if made to a file.
In case of pdf file,
The file will unlikely change.
What I want is that,
if I know msword or acrobat(these are examples) is running,
then I want to know which file was opened by the application.
Thanks..
|
|
|
|
|
There is no easy little API call to make. This will require a black belt in Windows internals. Not all expose an API to tell you what files that app has open, and most apps don't expose any kind of API at all.
You'd have to enumerate the handles of the process you're interested in, be it Word or Acrobat Reader. The problem is this technique is not documented anywhere, source code for it is very sparse, and it's all written in C++. You can find an example buried in the source for a Task Manager Extension, found right here[^] on CodeProject.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi There,
I want to be able to validate data entered by a user onto a form.
Different fields will have different validation requirements.
As an example, a text box may only allow numeric, alpha or alpha numeric entry and/or may have limitations on length or value.
I thought about inheriting a control from one of the standard forms controls and adding the validation code required but was thinking that this would make the application heavier than necessary because certain fields only require certain validation.
I wanted a way to add validation only where required so thought of creating a validator object which could have various validationRule objects added as required.
The validator could respond to events like textChanged on a text box and where it would then check the rules that had been applied.
I thought that the validationRule object would be either abstract or impliment specific interface.
I like the GOF 'Chain of Responsibility' pattern as a way of getting the rule objects to respond to a message from the validator however, I don't know how to ensure that all the rule objects have received/responded to the message.
Does this concept make sense? Is this the best way to go about validating user input? Is this pattern appropriate in this example?
Your thoughts/ideas/comments appreciated.
Regards
Wayne Phipps
____________
Time is the greatest teacher... unfortunately, it kills all of its students
View my Blog
|
|
|
|
|
Hello,
I am having a very strange problem with my .NET/C# application and I need help here. Thank you very much.
The problem is that when I run my GUI program on one laptop (xp/sp2), the size of the frame and controls are somehome changed/stretched. I tried to adjust all sorts of windows settings but no help. I then brought the source code to the machine and run the .NET VS (1.1), what I found is that the size (pixels) of the frame and controls are changed automatically. I don't understand why it happens...Could anyone know about this issue?
Regards,
John
|
|
|
|
|
Are you running an OS verion with Asian culture and/or using wide-screen monitor? (I had similar issue .. but couldnot find any relevant articles for the cause). I changed my entire UI to utilize docking (previously it used anchoring) and then UI problems disappeared.
- Malhar
|
|
|
|
|
Thanks for the help. But I've found the cause of the problem and the solution (workaound) as well.
The cuase of the issue is by changing the DPI setting (under Display -> Settings -> Advanced). When the DPI is set to 120 instead of default 96, some of the controls will get this problem, ie. the picture box. To fix it, there is a workaround to add the following code after the InitializeComponent() in formMain().
SizeF sf = Form.GetAutoScaleSize (this.Font);
this.AutoScaleBaseSize = sf.ToSize ();
John
|
|
|
|
|
Thanks .. I wonder if this is the cause of the problems I was having. Thanks for your input.
- Malhar
|
|
|
|
|
Hi,
I posted this message earlier and some one posted a link to an article. It helped, but still I am confused how to do it in my scenario.
I have a HomeForm (main form which has main()). In one of its meathod I have
<br />
PrimeInfoThread pTh = new PrimeInfoThread(this.pictureBox1,this.panel4,this.button1,this.button3,this.SLabel);<br />
Thread t = new Thread(new ThreadStart(pTh.ThreadProc));<br />
t.Start();
PrimeInfoThread is another class as follows
public class PrimeInfoThread<br />
{<br />
private System.Windows.Forms.PictureBox hPic ;<br />
private System.Windows.Forms.Panel hPan ;<br />
private System.Windows.Forms.Button but1 ;<br />
private System.Windows.Forms.Button but2 ;<br />
private System.Windows.Forms.Label slab ;<br />
<br />
public PrimeInfoThread(System.Windows.Forms.PictureBox hP,<br />
System.Windows.Forms.Panel hpanel,<br />
System.Windows.Forms.Button b1,<br />
System.Windows.Forms.Button b2,<br />
System.Windows.Forms.Label Sl) <br />
{<br />
hPic = hP;<br />
hPan = hpanel;<br />
but1 = b1;<br />
but2 = b2;<br />
slab = Sl;<br />
}<br />
<br />
public void ThreadProc() <br />
{<br />
EnumGetEDID InitEnumObj = new EnumGetEDID();<br />
InitEnumObj.AppInitEnum(slab); <br />
hPic.Hide();<br />
hPan.Hide();<br />
but1.Show();<br />
but2.Show();<br />
<br />
}<br />
<br />
}
In threadProc I call another class EnumGetEDID and call AppInitEnum(slab) where I pass the label. Inside AppInitEnum() I do 'slab.Text' to set the text values.
Now how do I make this Thread safe. Can anyone show it in my code.
Thanks a lot.
|
|
|
|
|
It seems to me that you're making this more complicated than it needs to be with the use of an entirely seperate class (PrimeInfoThread ) to run your other thread. Why don't you just have a method in your HomeForm class called ThreadProc() and then reference the UI components (labels, buttons, etc...) without passing them to another object. You can use the ParameterizedThreadStart delegate to pass the label 'slab ' - although it might make more sense to just pass the string value of its Text property if thats the only reason you need it... If you do that, then the following code should make it thread safe...
This goes in the routine that starts the thread:
Thread t = new Thread(new ParameterizedThreadStart(ThreadProc));
t.Start(this.SLabel); Then this in HomeForm :
private void ThreadProc(object data)
{
EnumGetEDID InitEnumObj = new EnumGetEDID();
InitEnumObj.AppInitEnum((Label)data);
UpdateUI();
}
private delegate void UpdateUIDelegate();
private void UpdateUI()
{
if (this.InvokeRequired)
{
this.BeginInvoke(new UpdateUIDelegate(UpdateUI));
return;
}
pictureBox1.Hide();
panel4.Hide();
button1.Show();
button3.Show();
} Hope this helps
Oh... forgot to say that this uses .Net Framework v2, since the ParameterizedThreadStart delegate isn't available in v1.1
Cheers,
Will H
-- modified at 15:41 Thursday 2nd February, 2006
|
|
|
|
|
If you use the 2.0, try to use the BackgroundWorker, it gives the abilty to update without the cross-thread exception.
|
|
|
|
|
Thanks. I've only recently started using 2.0 in the last few days. I'll definitely look into that one.
Cheers,
Will H
|
|
|
|
|
I just gave the BackgroundWorker class a whirl, and I don't think it does allow you to update the UI from a seperate thread. Maybe I miss-read your meaning, but I took the C# code from the example in the MSDN library (here[^]), then I added the line this.Text = percentComplete + "%"; just after worker.ReportProgress(percentComplete); in the ComputeFibonacci method (the one that's running on the seperate thread), and this caused a System.InvalidOperationException - a cross thread exception
Cheers,
Will H
|
|
|
|
|
You can only update UI controls on the thread that created them. Property updates and method calls on those controls must be marshalled back onto the UI thread. Lookup Control.Invoke for more information.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I know that. In this[^] thread I tried to explain that, but was told by eligazit that the BackgroundWorker class could let you get around this.
Cheers,
Will H
|
|
|
|
|