|
I always write my WinForm apps using an Outlook-style interface. Now I use the DevExpress libraries which has the very useful TabbedMdiManager which allows you to just create an MDI app and the control lays out the forms like Outlook or Visual Studio's tabbed form interface.
Prior to this, I used a Hashtable to hold my form collection. This is easy if you only allow a single instance of each form, as you can use the form's class name as the key. Otherwise, you need to establish a naming standard to ensure that you are manipulating the correct instance.
|
|
|
|
|
It says that 'The list that this enumerator is bound to has been modified. An enumerator can only be used if the list doesnt change.'
Of course the list will always be changing, so how do i ditch this enumerator thing?
|
|
|
|
|
You're using for each. For each will die when the list changes. You need to build an array of items to remove, then use a for loop to access it from the end to the start, removing the items one at a time.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I wonder what is the "best" way to provide a default implementaiton for an interface (without requiring to much typing).
Supose I have a "Document" interface, like
public interface IDocumentInfo
{
String Name { get; set; }
bool IsDirty { get; set; }
...
}
Now the default implementation is pretty straightforward, but I
(a) want to allow customization
(b) not have to clutter up the implementing class with all the method implementations
(c) not make it a base class
The only way I see to achieve both :
public class DocumentInfoImpl : IDocumentInfo
{
String name;
bool isDirty;
String Name { get { return name; } ... }
...
}
public interface IDocumentInfoAccess
{
IDocumentInfo DocumentInfo { get; }
}
public class MyDocument : IDocumentInfoAccess
{
private DocumentInfoDefaultImpl docinfdfltimpl = new DocumentInfoDefaultImpl();
public IDocumentInfo DocumentInfo { get { return docinfdfltimpl; } }
...
}
It feels overkill to have 3 entities, but it's the only thing I see.
what do you think? does it make sense?
We say "get a life" to each other, disappointed or jokingly. What we forget, though, is that this is possibly the most destructive advice you can give to a geek.
boost your code || Fold With Us! || sighist
|
|
|
|
|
If you just dislike the typing overhead, Visual Studio 2005 implements an interface for you in one single mouse click (right click on the interface name in the class definition -> "implement interface")
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I still have to provide the implementation (even if it's a call-forward to a default member). The source code gets cluttered with "meaningless" code, e.g. in my example the "document state" can be isolated easily (from a design view).
We say "get a life" to each other, disappointed or jokingly. What we forget, though, is that this is possibly the most destructive advice you can give to a geek.
boost your code || Fold With Us! || sighist
|
|
|
|
|
You said you don't want to make a base class out of it. How about making an extra base class so that implementations are easier while still allowing implementing the interface directly?
public class DocumentInfoBase
{
private string _name;
private bool _isDirty;
public virtual String Name {
get { return _name; }
set { _name = value; }
}
public virtual bool IsDirty {
get { return _isDirty; }
set { _isDirty = value; }
}
...
}
-- modified at 18:46 Monday 28th November, 2005
|
|
|
|
|
That's how i do it all the time .
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|
|
right, I could collapse the interface with the default implementaiton - seems OK
We say "get a life" to each other, disappointed or jokingly. What we forget, though, is that this is possibly the most destructive advice you can give to a geek.
boost your code || Fold With Us! || sighist
|
|
|
|
|
peterchen wrote: (c) not make it a base class
Since this requirement rules out using an abstract base class, I think your use of interfaces is the way to go. I see nothing wrong with it. Think of it as polymorphic delegation.
|
|
|
|
|
hi all
i wanted to know the coordinates of the mouse when i move on image in picturebox
this a method but work on the form only i tried it on the picturebox but it doesnt
protected override void OnMouseMove(MouseEventArgs mouseEv)
{
txtMouseX.Text = mouseEv.X.ToString();
txtMouseY.Text = mouseEv.Y.ToString();
}
hope to find solution
thanks in advance
haitham
|
|
|
|
|
As soon as you want to do more than display a picture, you're better off drawing it yourself instead of using a picturebox.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
at first thanks for replying me
i didnt understand wat u mean exactly by drawing it myself(how can i dow that)...can u reply with example?
and how can i make the coordinates of the mouse respond to it
thanks in advance.
haitham
|
|
|
|
|
class MyForm : Form
{
private Bitmap bitmap;
protected void OnPaint(object sender, PaintEventArgs ea)
{
if (bitmap != null)
{
e.Graphics.DrawImage(bitmap, etc
}
}
}
Now you're drawing your own bitmap, and you'll get all the mouse messages, as it's drawn on your form, not on a control on the form.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I want to just have the process name, even if it still has the brackets around it. But i also have
foreach(Process kill in this.listbox1.SelectedItems)
{
kill.Kill();
}
so the item still needs to be of type 'Process'
Its just the string that the box displays that i want to change.
|
|
|
|
|
Define the following in your project:
public struct ProcessWrapper
{
public ProcessWrapper( Process process ) { p = process; }
public Process p;
public override string ToString() { return p.ProcessName; }
} Now, when you add items to your ListBox , just do the following:
listBox.Add( new ProcessWrapper( p ) ); and everything should look the correct way. Later, in your code, you can do the following:
foreach( ProcessWrapper pw in listbox.SelectedItems )
{
pw.p.Kill();
} That should take care of your needs.
DISCLAIMER: The struct ProcessWrapper does not implement recommended data member hiding and the like. This is really more for your convenience so I did not go into it.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
How do I specify formatting options for String.Format? I found something on how to add custom formatting for a class of mine, but nothing how to format numbers (e.g. left-pad them with zeroes)
We say "get a life" to each other, disappointed or jokingly. What we forget, though, is that this is possibly the most destructive advice you can give to a geek.
boost your code || Fold With Us! || sighist
|
|
|
|
|
|
thanks -
out of curiosity: what search string did you use?
We say "get a life" to each other, disappointed or jokingly. What we forget, though, is that this is possibly the most destructive advice you can give to a geek.
boost your code || Fold With Us! || sighist
|
|
|
|
|
string.format C# number site:msdn.microsoft.com
The site: is the vital bit, in my experience. Even then, I wandered through about 4 links on MSDN before I found that one. I've looked at it often, I knew exactly what I was looking for.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Would someone please show me how to connect to my database in MSDE using c# Visual Studio!
I cannot figure it out to save my life.... i have already spent far to much time on this
Please list the necessary steps to connect to my MSDE database.
please explain very clearly like you are explaining this to your 88 year old grandma!
Is their multiple ways to connect? I see a wizard of some sort? help me out here
Thanks in advance
Kourvoiser "13 Thieves of the Diamond"
-- modified at 17:43 Monday 28th November, 2005
|
|
|
|
|
MSDE is SQL Server. Connect the same way you would to SQL Server. The web is full of examples.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I am attempting to call legacy c code from C#. I've compiled the c code into a dll in VS.net and am trying to call one of its functions from C#. One of the parameters that the c function is looking for is a pointer to a structure( c_func(C_DEF_STRUCT *cStr) ). The structure is defined as follows:
typedef struct C_DEF_STRUCT {
char aChar;
long a_len;
long b_len;
long c_len;
long d_len;
long e_len;
long f_len;
long unsigned char *aPtr;
long unsigned char *bPtr;
long unsigned char *cPtr;
long unsigned char *dPtr;
long unsigned char *ePtr;
long unsigned char *fPtr;
long unsigned char *gPtr;
} C_DEF_STRUCT;
I created a struct in C# as follows:
[StructLayout(LayoutKind.Sequential)]
public struct DEF_STRUCT
{
public char aChar;
public Int32 a_length;
public Int32 b_length;
public Int32 c_length;
public Int32 d_length;
public Int32 e_length;
public Int32 f_length;
public Int32 g_length;
public Int32 size;
public byte[] aPtr;
public byte[] bPtr;
public byte[] cPtr;
public byte[] dPtr;
public byte[] ePtr;
public byte[] fPtr;
public byte[] gPtr;
}
On the C# side, I before calling the C function I did the following:
DEF_STRUCT myStruct = new DEF_STRUCT();
myStruct.aPtr = new byte[5000];
Then I proceeded to fill aPtr.
When calling the C function, I'm passing myStruct along as a reference ( c_func(ref myStruct) ).
The contents of aPtr is not getting sent over correctly. I get an address on the C side, but the contents of the array does not match what is on the C# side.
I'm not sure how to solve this problem. Any suggestions would be great.
|
|
|
|
|
I want to go to a page like:
http://www.modaco.com/index.php?act=portal, mow in this case you can just go to http://www.modaco.com, but what about other pages that don't end in .co.uk, or .com, or .whatever.
|
|
|
|
|
How can i get windows default currency symbol as i can see it in windows reginal setting?
Thanks in advance
|
|
|
|