|
ICustomTypeDescriptor wrote:
Now the problem is: how would you implement this hierarchy in C#?
In C++, this might be a candidate for multiple inheritence. With C#, interfaces are a poor substitute, because as you say, you end up writing the same code in both classes.
However, you still may want to use an interface so that some other class can utilize your specialized class' methods and properties. So, to avoid duplicating the same code, you write a class that implements the functionality, and the classes that implement the interface instantiate the helper class and call its methods.
Does that help?
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
|
Well, I think I can't instantiate one of the classes and call its methods. So I have to double the code?
So I have another question - it happens to be a DLL, so is it possible to write the dll in Managed C++, using multiple inheritance, and then use it in C#?
|
|
|
|
|
I have a process that starts and runs MS Word for about 10 seconds. Sometimes Word seems to hang; it stays open for 'ever'. Is there an way that I can run a process2 independently of process that checks to see if Word is running and if it is, if it has been open for about a minute, and if it has, to stop it? Thanks in advance.
|
|
|
|
|
You can do the following. Run the follong code to see if MS Word is running and if it is it will kill the process.
using System.Diagnostics;
private Process[] WordProcessList;
.....
int index;
WordProcessList = Process.GetProcessesByName("WINWORD");
for( index = 0; index < WordProcessList.Length; index++)
{
WordProcessList[index].Kill();
}
|
|
|
|
|
How to develop a dropdown list like control from scratch.
|
|
|
|
|
Just atextbox and a flat button in the right and some other textbox without border to actlike the list.
|
|
|
|
|
yes, but when i tried to do that, the text box is not overlaping on to other controls on the form. and when i use the control inside a panel/group box the part of the textbox which is out of the panel is not visible?
is there anyway to avoid that??
|
|
|
|
|
Just try BringToFront(); method of this textbox
|
|
|
|
|
it doesn't help since the parent of the textbox used as a list is the control not the form! when BringToFront() is used it brings the textbox to the front of the control but not the form on which the contol is? currently i have a work around which changes the parent of the textbox and positions it so that it aligns with the rest of the control. it works.
the problem is i don't want to change the parent of the textbox just to draw it on top of the z-order
|
|
|
|
|
I downloaded a project in C# and would like to compile it. There is no project or solution file available, so, I created a new project and put everything there.
PROBLEM:
There are many files stored in different sub-directories (of the project directory). The files in each directory belong to the same namespace.
For example :
In Main.cs of the project directory contains:
using ABC.namespace1
using ABC.namespace2
and in the directory {project dir}/ABC/namespace1, there is a bunch of class files declaring as: namespace ABC.namespace1
MY QUESTION:
Do I need to copy all the files of the sub-directories to the project directory to compile it or there is a setting in Visual Studio that allows this. Right now, when I tried to compile it, I got the message:
"The type or namespace name 'namespace1' does not exist in the class or namespace ABC. Are you missing assembly references ?"
Thanks a lot for any help
|
|
|
|
|
It may be a .dll with it and then you may have a reference first to it.
|
|
|
|
|
i want to write to program for uploading file to webserver, but i don't know the mechanism of uploading file
Show me detail if you can
Thank you
|
|
|
|
|
You could use something simple like the following:
WebClient <code>Client</code> = new WebClient();
Client.UploadFile("http://www.MyWebsite.com/index.aspx", "C:\MyFile.aspx");
Note: You should also consider providing checkups for your upload mechanism (such as checking if the file does exist, or that its contentLength is greater zero).
Hope this helps
Regards,
Polis
Can you practice what you teach?
|
|
|
|
|
Hi,
Should I use TableLayoutPanel for my Form with FixedDialog style?
I can't understand when i need in TableLayoutPanel.
Best regards.
|
|
|
|
|
You should use TableLayoutPanel when you want your controls laid out in rows and columns.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|
|
Hi,
I want to ask how to execute a static function in a user created application domain. I am trying to run following sample code. But it seems that the method that I am trying to execute in my created domain always executed in the default created domain (caller domain).
public void ExitProcessTest()
{
string applicationTitle = "ApplicationToBeKilled";
Assembly asm1 = Assembly.GetAssembly(typeof(OSP.Forms.ErrorBox));
AppDomainSetup ads = new AppDomainSetup();
ads.ApplicationBase = @"file:///C:\Components.NET\Testing\TestProject\bin\Debug\";
ads.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory;
ads.ApplicationName = applicationTitle;
AppDomain newappDomain = AppDomain.CreateDomain(applicationTitle, null, ads);
Assembly asm = newappDomain.Load(asm1.FullName);
Type type = asm.GetType("OSP.Forms.ErrorBox");
type.InvokeMember("ExitProcess", BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, new object[] { applicationTitle });
Thread.Sleep(15000);
}
public static void ExitProcess(string applicationTitle)
{
//It's better to close the application, otherwise, could throw many other errors
try
{
ApplicationTitle = applicationTitle;
Thread exitThread = new Thread(new ThreadStart(ApplicationExitThread));
exitThread.Name = "ExitThread";
exitThread.Start();
}
catch (Exception exc) { ShowError(exc, "Osp.Shared", null, "script_error@etb.bel.alcatel.be"); }
}
private static string ApplicationTitle;
private static void ApplicationExitThread()
{
try
{
Form f = new Form();
f.TopMost = true;
f.Size = new Size(370, 60);
f.BackColor = Color.Red;
f.FormBorderStyle = FormBorderStyle.None;
Label lbl = new Label();
lbl.BorderStyle = BorderStyle.FixedSingle;
lbl.ForeColor = Color.White;
lbl.Font = new Font("Verdana", 10, FontStyle.Bold);
lbl.TextAlign = ContentAlignment.MiddleCenter;
lbl.Dock = DockStyle.Fill;
lbl.Text = "The " + ApplicationTitle + " will exit in few seconds.\nSorry for the inconvenience.";
f.Controls.Add(lbl);
f.StartPosition = FormStartPosition.CenterScreen;
f.Show();
f.TopMost = true;
f.Invalidate();
f.Update();
Thread.Sleep(1000);
for (int i = 5; i > 0; i--)
{
lbl.Text = "The " + ApplicationTitle + " will exit in " + i + " second" + (i > 1 ? "s" : "") + ".\nSorry for the inconvenient.";
lbl.Update();
Thread.Sleep(1000);//to ensure the error mail is sent!
}
//Process.GetCurrentProcess().Kill();
MessageBox.Show(AppDomain.CurrentDomain.FriendlyName);
}
catch (Exception exc) { ShowError(exc, "Osp.Shared", null, "script_error@etb.bel.alcatel.be"); }
}
|
|
|
|
|
Hey
I'm trying to find a way to get the name of a file in a FileInfo object.
I DO NOT mean this:
out of, c:\blabla.exe --GET--> blabla.exe
BUT this:
out of, c:\blabla.exe --GET--> blabla
anyone can help me with this???
|
|
|
|
|
|
Thanks!
that could really make my life easier!!! (I wrote this code in the hard way!)
|
|
|
|
|
I wrote my first own control, it derives from Windows.Forms.Control, and it's a simple ellipse label. The code for drawing:
<br />
protected override void OnPaint(PaintEventArgs pe) {<br />
Graphics g = pe.Graphics;<br />
Brush foreBrush = new SolidBrush(ForeColor);<br />
Brush backBrush = new SolidBrush(BackColor);<br />
g.FillEllipse(backBrush, ClientRectangle);<br />
<br />
StringFormat fmt = new StringFormat();<br />
fmt.Alignment = StringAlignment.Center;<br />
fmt.LineAlignment = StringAlignment.Center;<br />
g.DrawString(Text, Font, foreBrush, ClientRectangle, fmt);<br />
<br />
base.OnPaint(pe);<br />
}<br />
}<br />
The question - how to implement so that the label wraps text if it is to long to fit in a single line?
|
|
|
|
|
Hi, you can use MeasureString to give you the length of the string in drawing units (pixels) and compare the width of your control - border (or just client width if there is not an NC portion). Then of course, just extend the height of your control by the height of the current font, split, and wrap the line.
You can get the font height with the Font property and call its Height property but make sure you use your graphics object's MeasureString method to get the length of the string in question.
hope that is enough detail for you, if not let me know and i'll try to help further.
|
|
|
|
|
That'll do, thanks a lot man!
|
|
|
|
|
How to i create a website that can send sms`s ???
Thanks in advance !;)
|
|
|
|
|
You could implement a website with a server backend that sends SMS's. Search Codeproject, there are several articles (such as this one[^]) that describe how you can send SMS messages.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Horrific Minnesota Radio
Judah Himango
|
|
|
|