|
I have assigned a string[] object to a property grid and I am able to view and edit the elements. I have turned off the default editor (i.e. the ellipsis is no longer shown), by implementing an extension of the UITypeEditor class and overriding the GetEditStyle method and setting UITypeEditorEditStyle to None. I have called this class NoEditor.
However next to the string[] object in the property grid there appears "String[] Array". I do not want to show this. So I wrote this class:
internal class HeadingListConverter : ExpandableObjectConverter
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is string[])
{
return "";
}
return base.ConvertTo(context, culture, value, destType);
}
}
These two lines are added to the property,
[EditorAttribute(typeof(NoEditor),typeof(UITypeEditor)),
TypeConverter(typeof(HeadingListConverter))]
However, although now the object displays the text I require next to it, the result is that the string[] object is displayed as a System.String[]. So it displays the properties of the System.String[] object like rank and length rather than the elements which I require.
What am I doing wrong? I hope I have explained the problem clearly - any help is appreciated.
|
|
|
|
|
Got it now!!! FYI, extend from ArrayConverter instead of ExpandableObjectConverter.
|
|
|
|
|
Is it possible to get floating panes for windows applications in C# .... just like the 'properties' and 'solution explorer' panes in the Visual Studio .NET IDE
-- modified at 3:48 Sunday 19th March, 2006
|
|
|
|
|
For VS2005, you need to install VSIP sdk, its an extensible sdk. Using VSIP you can create floating pane like properties, solution explorer etc. Also you can implement functionality similar to floating pane.
Regards,
Shiby
|
|
|
|
|
I want to create a button on the Visual Studio standard toolbar (an addin basically) which will give me the path of the currently opened project (solution file) in the IDE. I created a an addin with the following code - 'Application.StartupPath'. However all that this button does is give me the path of the IDE (i.e. devenv.exe). I want the path of the currently opened project. Any suggestions guys.
|
|
|
|
|
If what you are trying to retive is the path of your application when it is running,
//you can use the following function that will return the oath string
Directory.GetCurrentDirectory()
Adn Dont forget to include
using System.IO;
|
|
|
|
|
You'll need to get a reference to an instance of the DTE interface (I can't remember how you do this), from there on you go through something like this:
DTE.Solution.Projects, I don't know how to get the currently opened project but once you have then then each Project class contained inside Projects has a FileName property which is what you want.
Sorry I don't know how to get the active project but this I think is the correct way to go about it.
Ed
|
|
|
|
|
I would like to capture the specific events of running instances of IE. I am using the ShellWindows to get all the running instances of IE. I can get the some of the events to fire, such as OnTitleChange. But, I cannot get the WindowSetLeft event to fire. I am trying to use this event so that I know when the user is moving one of the IE windows on the screen. I need to know the position of each IE window when it changes. Thanks for the help in advance.
using System;
using System.IO;
using SHDocVw;
using System.Text;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace JTCG.JWS.Browse.BrowseTOC
{
public class ActivityMonitor
{
[DllImport("User32.Dll")]
public static extern void GetWindowText(int h, StringBuilder s, int nMaxCount);
//variable declaration
private SHDocVw.InternetExplorer browser;
private SHDocVw.ShellWindows shellWindows;
private ArrayList Current_IE_Handles;
#region Constructor
public ActivityMonitor()
{
Current_IE_Handles = new ArrayList();
shellWindows = new SHDocVw.ShellWindowsClass();
shellWindows.WindowRegistered += new SHDocVw.DShellWindowsEvents_WindowRegisteredEventHandler(shellWindows_WindowRegistered);
shellWindows.WindowRevoked += new SHDocVw.DShellWindowsEvents_WindowRevokedEventHandler(shellWindows_WindowRevoked);
}
#endregion
// THIS EVENT IS FIRED WHEN THE A NEW BROWSER IS CLOSED
private void shellWindows_WindowRevoked(int z)
{
//variable declaration
string filnam;
ArrayList Closed_IE;
StringBuilder sb;
//variable initialization
Closed_IE = new ArrayList();
sb = new StringBuilder(1024);
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
filnam = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filnam.Equals("iexplore"))
{
Closed_IE.Add(ie.HWND.ToString());
}
}
for (int i=0; (i< this.Current_IE_Handles.Count); i++)
{
bool check = false;
for (int j=0; (j<Closed_IE.Count); j++)
{
if (Convert.ToInt32(this.Current_IE_Handles[i]) == Convert.ToInt32(Closed_IE[j]))
check = true;
}
//IE handle not in ArrayList
if (check == false)
{
this.Current_IE_Handles.RemoveAt(i);
break;
}
}
}
// THIS EVENT IS FIRED WHEN THE A NEW BROWSER IS OPEN
private void shellWindows_WindowRegistered(int z)
{
//variable declaration
string filnam;
StringBuilder sb;
//variable initialization
sb = new StringBuilder(1024);
//loop through all windows in shell
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
filnam = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filnam.Equals("iexplore"))
{
browser = ie;
bool check = true;
for (int i=0; (i<Current_IE_Handles.Count); i++)
{
if (Current_IE_Handles[i].ToString() == browser.HWND.ToString())
{
check = false;
break;
}
}
if (check == true)
{
Current_IE_Handles.Add(browser.HWND.ToString());
//-----------------------------------------------------------------
//-------------------My code below---------------------------------
IWebBrowserApp m_WebBrowserApp = (IWebBrowserApp)browser;
//set up events may want to make below code a method
if (m_WebBrowserApp != null)
{
//Application.DoEvents();
DWebBrowserEvents2_WindowSetLeftEventHandler DSetLeft = new DWebBrowserEvents2_WindowSetLeftEventHandler(WindowSetLeft);
browser.WindowSetLeft += DSetLeft;
DWebBrowserEvents2_TitleChangeEventHandler DTitleChangeE = new DWebBrowserEvents2_TitleChangeEventHandler(OnTitleChange);
browser.TitleChange += DTitleChangeE;
}
//-----------------------END of my code----------------------------
}
}
}
}
static void OnTitleChange(String Text)
{
MessageBox.Show("Title changes to " + Text);
}
static void WindowSetLeft(int Left)
{
MessageBox.Show("set left : " + Left.ToString());
}
}
}
Mario Williams
Systems Analyst (DoD)
Eglin Air Force Base, FL
|
|
|
|
|
Say I have put some standard Button in a form.
Then I created a ButtonEx control inherited from Button.
How do I quickly replace all Button in the form with ButtonEx, and copying the properties of Button to ButtonEx automatically?
Thanks.
|
|
|
|
|
Open the code view, and use a simple search and replace.
|
|
|
|
|
Thanks a lot
|
|
|
|
|
Hello,
Thanks for your visit.this is my first message.
i am very love the Menu and toolbar in VS2005,but i am a new person in C#,
can some one give me a think about how to write it?
or give me some source code about it.
thanks to everyone,with best wishes.
PS:My english is pool,if have some mistake in this message,don't laugh me.
very good
|
|
|
|
|
|
Hi,
I am learning C# gui, I was wondering how to match GUI similar to RealPlayer, MusicMatch, iTune or Windows Media Player.
Mainly - Nom Rectangular GUI, rounded buttons, Goodlooking scrollbar etc???
Any help is appreciated.
Thanks in advance.
|
|
|
|
|
|
|
i have the folowing class:
class MyClass<br />
{<br />
public MyClass(string str)<br />
{<br />
Str = str;<br />
}<br />
<br />
public string Str;<br />
<br />
public override string ToString()<br />
{<br />
return Str;<br />
}<br />
}
now lets add some items to a ComboBox:
comboBox1.Items.Add(new MyClass("aaa"));<br />
comboBox1.Items.Add(new MyClass("bbb"));<br />
comboBox1.Items.Add(new MyClass("ccc"));
and now....
suppose that i want to change the first item Str member to "ddd":
the following line doesn't work:
((MyClass)comboBox1.Items[0]).Str = "ddd";
But the following will work:
comboBox1.Items[0] = new MyClass("ddd");
It seems that a copy of the item is returned from the object collection in the ComboBox.
Does anyone know how it is possible to change the item directly without replacing it?
Thanks in advanced, Ilan
|
|
|
|
|
Have you tried invalidating the combobox after you change the Str property?
I've just re-tried this code out and it worked as you want and as I expected.
Sorry, problem with your dev system not .NET
Ed
|
|
|
|
|
I am sorry - it doesn't work even if i validating the combo box:
here is the complete code again:
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
comboBox1.Items.Add(new MyClass("aaa"));<br />
comboBox1.Items.Add(new MyClass("bbb"));<br />
comboBox1.Items.Add(new MyClass("ccc"));<br />
<br />
((MyClass)comboBox1.Items[0]).Str = "ddd";
comboBox1.Invalidate();<br />
}<br />
...<br />
...<br />
...<br />
class MyClass<br />
{<br />
public MyClass(string str)<br />
{<br />
Str = str;<br />
}<br />
<br />
public string Str;<br />
<br />
public override string ToString()<br />
{<br />
return Str;<br />
}<br />
}<br />
<br />
Well, i am usin VS2005.
|
|
|
|
|
That doesn't work, because the combobox is already in the state of invalid when you try to invalidate it. The combobox has already detected that you have added items to it, and is only waiting for your code to end to redraw itself. When the items were added the ToString method was called to get their values, and those are the values that will be used to redraw the combobox. The combobox hasn't detected that you have changed the underlying data of one of the items since then.
If you change the item and invalidate the combobox once the combobox has been drawn, for an example on the click event of a button, it will work.
---
b { font-weight: normal; }
|
|
|
|
|
I am sorry - i tried and tried and it doesn't work, pay attention that the following WILL work fine:
<br />
comboBox1.Items.Add(new MyClass("aaa"));<br />
comboBox1.Items.Add(new MyClass("bbb"));<br />
comboBox1.Items.Add(new MyClass("ccc"));<br />
<br />
((MyClass)comboBox1.Items[0]).Str = "ddd";
<br />
for(int i = 0; i < comboBox1.Items.Count; i++)<br />
{<br />
comboBox1.Items[i] = comboBox1.Items[i];<br />
}<br />
<br />
and i also trie to put the code of changing the item in the click event - NOTHING - NADDA - the combo box doesn't reflect the change.
If you succeed in this simple task it would be nice if you POST this code.
Thanks again - Ilan
|
|
|
|
|
Ok, problem sorted
There is a method in the reflector class called RefreshItem(int index) which when called redraws the item, looking in reflector at the code all it does is this:
comboBox1.Items[0] = comboBox1.Items[0];
Which forces the combobox to reload the data. What is happening is that becase you are changing a property of the item not the actual item itself the combobox has no way of knowing when an item has been changed because the item class does not raise an event stating that it has had a property changed.
Now for the problem, ComboBox.RefreshItem(int index); is protected overrides so you cannot call it, but by looking in reflector you can see what you're supposed to do and do it yourself.
So in summary after you have changed the property (Str), do this:
comboBox1.Items[index] = comboBox1.Items[index];
It works
Thanks for pointing out this "bug" to me though
Ed
|
|
|
|
|
Well Ed - Now we agree on the problem and its solution
However - when you say "reflector" what do you mean, i don't know this tool.
Ed.Poore wrote: ow for the problem, ComboBox.RefreshItem(int index); is protected overrides so you cannot call it, but by looking in reflector you can see what you're supposed to do and do it yourself
Thank again for sharing my problem.
Ilan
|
|
|
|
|
Well i think i found it "Reflector for .NET" from Lutz Roeder... Or maybe you are using other tool?
|
|
|
|
|
No that's the tool, you havn't come across it before?
It's a godsend
Ed
|
|
|
|