|
You have a few options, you can as previously stated use the is keyword and see if it's the type you are looking for.
An alternative is to actually look at the BaseType :
Type t = ActiveMdiChild.GetType();
Type baseClass = t.BaseType;
object something = Activator.CreateInstance(baseClass);
However, unless there is a common base class that you can cast to so that you can use it then you are back to checking the actual type and casting to that.
So depending on what you have and what you need you can either have a series of if statements checking for the types or the above method where you will be able to create and use your base class without necessarily knowing exactly what it is.
My current favourite quote is: Punch them in the face, see what happens!
-SK Genius
|
|
|
|
|
Hmm.. This looks good but i wont get the methods of the base class object in the intellisense here. Is there a way of getting that too? Maybe i am asking for too much here.
Regards,
Samar
|
|
|
|
|
Check out this article:
The case for a generic C# converter using operators[^]
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I am having an issue with this. I need to create a folder in the current users application data folder to store settings but I cannot. Every time I try to use Directory.CreateDirectory(Environment.SpecialFolder.MyDocuments + "/JFE/Settings") Or anything else under SpecialFolder it will just create a folder in the application's directory with a name like Personal then inside this directory it will make the folders I requested. Why does it do this? I printed out the string for the special folder and looked at it and it is correct but for some reason it creates my folders in the current program's directory.
Y*Live Long And Prosper*Y
|
|
|
|
|
Try this:
Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "JFE/Settings"))
Good luck
PS: The big change is Environment.GetFolderPath. Path.Combine I just inserted because it's better to use that than concatenate the path using "+"
|
|
|
|
|
Worked! Thanks!
Y*Live Long And Prosper*Y
|
|
|
|
|
Of course! Learn from the master, my young jedi...
|
|
|
|
|
i have developed a simple c# desktop windows app when i take it to another pc its color automatically changed to black or another , can any one help that how can i prevent from this prob
|
|
|
|
|
With that little information, no - no-one can help.
We would need a better description of the problem, and probably a small fragment of relevant code (use the "code block" widget to preserve formatting) to show us what you are doing.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
Windows controls appereance by default depends on selected theme in windows.You can avoid it by creating your own theme independant styles for each of them.Similar job has already been done for MFC here at cp ^.
Life is a stage and we are all actors!
|
|
|
|
|
hello every one. am trying to create Image from byte array in my page. First i create the image by System.Drawing.Image then am trying to convert System.Drawing.Image to System.Web.UI.WebControls.Image. but the compiler says "Cannot convert type 'System.Drawing.Image' to 'System.Web.UI.WebControls.Image'". So any one please help me.Thxs.
|
|
|
|
|
At first you have choosen wrong forum to post your question.You should post it to ASP.NET forum.
This article explains how to solve it and lots more.
Life is a stage and we are all actors!
|
|
|
|
|
I want to register a hotkey(for example:Ctrl+Shift+A) to do such a thing:
When I press the hotkey, I hope it will input a sentence "Hello!" at the position of current cursor in a outer active window, such as Microsoft Word,NotePad,etc.
Now I have completed the registration of the hotkey with:
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool RegisterHotKey(
IntPtr hWnd,
int id,
uint fsModifiers,
Keys vk
);
.....
RegisterHotKey(Handle, 150, 2|4, Keys.A);
.....
private void ProcessHotkey(Message m)
{
IntPtr id = m.WParam;
string sid = id.ToString();
switch (sid)
{
case "150": SayHello(); break;
.....
}
}
.......
private void SayHello()
{
MessageBox.Show("Hello!");
}
It works well! When I press Ctrl+Shift+A ,a messagebox will say "Hello!". But how to get the current active window, and input the text to current cursor, no matter where the cursor is and which application it is in?
|
|
|
|
|
Have a look at the SendKeys class. It may be sufficient for your needs.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
I try to use this:
Process myPro = new Process();
myPro.StartInfo.FileName = @"notepad.exe";
myPro.Start();
myPro.WaitForInputIdle(1000);
SendKeys.SendWait("Hello!");
It's OK. I created this process "myPro", but how to get the process of the current active window?
can you give me the detailed code? Thanks.
|
|
|
|
|
imbiz wrote: can you give me the detailed code?
No. First of all, this isn't a "give me code" web site. People here ask specific questions, while others provide advice and suggestions.
Second, it depends on circumstances. In simple situations, the process your app launches, will become the active app with the topmost window, and hence get whatever SendKeys sends. But then, the user (or a second automation-oriented app, or any app that feels like it) may suddenly cause another window, maybe another app, to get focus. The safer way is to check using GetForeGroundWindow (which requires P/Invoke techniques), or to send a message using SendMessage, or to create real inter-process communication by adapting both applications.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Thank you! I have found the solution! I compared all the handles(Toint32) of processes with Getforegroundwindow's, but it will tell me there more than one window. I observed that just the first one is the real active window, so I use "break" to quit "foreach". It works! That's so strange.
The code:
Process mypro=null;
foreach (Process thisproc in Process.GetProcesses())
{
if (thisproc.MainWindowHandle.ToInt32() == GetForegroundWindow().ToInt32())
{
mypro = thisproc;
break;
}
}
try
{
SendKeys.Send(@"{ENTER}\begin{{}split{}}{ENTER} &= {ENTER} &= {ENTER}\end{{}split{}}{ENTER}");
}
catch (System.NullReferenceException e)
{
}
Now, if I press the hotkey Ctrl+Shift+A, it will send some strings or commands to any active window. I use this to input some fixed blocks which need to be repeated for many times.
modified on Saturday, June 5, 2010 3:47 AM
|
|
|
|
|
Hi
can anyone help with the following
i use filesystemwatcher to watch a folder and add a new entry into a listbox everytime a new file is created, there is a second listbox that duplicates whats in the first but with some code allows me to change the file name via a text box, works ok as long as the item in listbox2 is highlighted when i change text, however if the listbox updates while i'm in process of changing text it removes the highlight from the item i'm editing and crashes if i press enter to confirm new file name.
Ther error i get is no doubt due to it not knowing what index to change as none are highlighted.
So how can i get it to keep the file i am changing name of highlighted until i enter the new text.
private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
{
listBox1.Items.Add(e.FullPath);
listBox2.Items.Add(e.FullPath);
listBox1.SelectedIndex = listBox1.Items.Count - 1;
listBox1.SelectedIndex = -1;
listBox2.SelectedIndex = listBox2.Items.Count - 1;
listBox2.SelectedIndex = -1;
}
private void listBox1_Click(object sender, EventArgs e)
{
listBox2.SelectedIndex = listBox1.SelectedIndex;
}
private void listBox2_Click(object sender, EventArgs e)
{
int itemSelected = this.listBox2.SelectedIndex;
string itemText = this.listBox2.Items[itemSelected].ToString();
Rectangle r = this.listBox2.GetItemRectangle(itemSelected);
this.textBox1.Location = new System.Drawing.Point(r.X + 217, r.Y + 520);
this.textBox1.Size = new System.Drawing.Size(r.Width + 4, r.Height - 10);
this.textBox1.Visible = true;
this.textBox1.Text = itemText;
this.textBox1.Focus();
this.textBox1.SelectAll();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
this.listBox2.Items[this.listBox2.SelectedIndex] = this.textBox1.Text;
this.textBox1.Visible = false;
}
if (e.KeyChar == 27)
this.textBox1.Visible = false;
}
|
|
|
|
|
The solution is very simple.
Just store the selectedindex value in some global variable,
and keep listbox2's item selected while some new item is
added to it.
Track listbox2's CollectionChanged event and write code to make
the previously selected item (which is now not selected bcoz
new item is added to listbox2) selected using our global variable
in which we stored selectedindex of listbox2.
And ya update the global variable on following event.
private void listBox1_Click(object sender, EventArgs e)
{
listBox2.SelectedIndex = listBox1.SelectedIndex;
Global_Listbox2_selectedIndex = listBox1.SelectedIndex;
}
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Thanks for reply, i've removed second list box as i dont think it has any use for what i want it to do.
i now use the textbox to change name of listbox1 selecteditem and i am now trying to rename the actual file with "file.move" but i'm having a problem with second part of "file.move"
private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
{
listBox1.Items.Add(e.FullPath);
listBox1.SelectedIndex = listBox1.Items.Count - 1;
listBox1.SelectedIndex = -1;
}
private void listBox1_Click(object sender, EventArgs e)
{
int itemSelected = this.listBox1.SelectedIndex;
string itemText = this.listBox1.Items[itemSelected].ToString();
Rectangle r = this.listBox1.GetItemRectangle(itemSelected);
this.textBox1.Location = new System.Drawing.Point(r.X + 217, r.Y + 520);
this.textBox1.Size = new System.Drawing.Size(r.Width + 4, r.Height - 10);
this.textBox1.Visible = true;
this.textBox1.Text = itemText;
this.textBox1.Focus();
this.textBox1.SelectAll();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
File.Move(Path.GetFullPath(listBox1.SelectedItem.ToString()), this.textBox1.Text.ToString()+".avi" );
this.listBox1.Items[this.listBox1.SelectedIndex] = this.textBox1.Text;
this.textBox1.Visible = false;
}
if (e.KeyChar == 27)
this.textBox1.Visible = false;
It renames the file ok but moves file to debug directory of my project instead of leaving it where it is and just renaming it
kenny
|
|
|
|
|
hi everone,
I want to change/apply new themes on controls of win form in C# VS 2005.
I s there any open source or any other dll ?
Thanks in adv.
|
|
|
|
|
How many times are you going to ask this question?
Nobody can answer it for you if you don't explain exactly what you want to change about the controls....
|
|
|
|
|
You've asked a similar question before.
There are some third party dll's available - see here.
My signature "sucks" today
|
|
|
|
|
He's asked a lot more times than once before...
|
|
|
|
|
How many times are you going to ask this question and ignore the answers you've been given?
|
|
|
|