|
How can I programmatically push a toolbar button?
foreach (ToolBarButton refBtn in toolBar1.Buttons)
{
if refBtn meets some condition then click it. Just like a mouse click.
refBtn = left moust click;
}
thanks
|
|
|
|
|
If the ToolBar.ButtonClick event handler is accessible (i.e., in the same class or with an access modifier that allows it to be access from outside your class), then just call it like so:
public class MyForm : Form
{
private ToolBar tb;
public MyForm()
{
tb = new ToolBar();
Controls.Add(tb);
tb.ButtonClick += new ToolBarButtonClickEventHandler(tb_ButtonClick);
}
private void tb_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
{
}
public void ClickButton(ToolBarButton b)
{
tb_ButtonClick(tb, new ToolBarButtonClickEventArgs(b));
}
} Otherwise, you'll have to P/Invoke the SendMessage API and send the TB_PRESSBUTTON message like so:
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(
IntPtr hWnd,
uint msg,
IntPtr buttonID,
IntPtr press);
public void ClickButton(ToolBar tb, int position)
{
if (tb != null)
{
SendMessage(tb.Handle, 0x0403, new IntPtr(position), new IntPtr(1));
SendMessage(tb.Handle, 0x0403, new IntPtr(position), new IntPtr(0));
}
} See the Platform SDK documentation for the TB_PRESSBUTTON message for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
That was a fantastic answer!
thank you
|
|
|
|
|
I was wondering if anybody knows how to disable the version auto increment feature in Visual C# .NET???
|
|
|
|
|
Get rid of the asterisk in the AssemblyVersionAttribute typically found in the AssemblyInfo.cs file and use your own 4-digit versioning scheme. This is best for larger solutions anyway. We have our own scheme we used that I designed for the ~60-project solution I maintain. Especially with late-binding, automatic version is a real pain.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I tried that and set the version to 1.0.1.1 and when I built it it still incremented. Any ideas?
Heath Stewart wrote:
We have our own scheme we used that I designed for the ~60-project solution I maintain.
Would it be possible for you to share this system?
|
|
|
|
|
Something else is wrong, then. So long as you have something like this:
[assembly: AssemblyVersion("1.0.1.1")] You'll never have an incremental version number (and it's technically not incremental - see the attribute documentation in the .NET SDK). Also make sure that if you use the AssemblyFileVersionAttribute that you fix that as well, although I don't think that accepts an asterisk.
Make sure that you have project references as well instead of assembly references (when you add a reference, click the Project tab instead of selecting an assembly) and make sure that you have one and only one AssemblyVersionAttribute defined at the assembly level (prefixed with assembly: ). You shouldn't have any problems. If you do, you have something wrong.
And, no, I can't share that system. It's our flagship product.
If you want the versioning system I use, it's almost the same as what the C# compiler uses. The major and minor versions (the first two) you set. The third is the number of days since January 1, 2000, and the last is incremented to signify minor changes. We don't change that number much except for minor bug fixes since Fusion requires that a new assembly version exists or it won't download it (we use touchless-deployment over the 'net). The build is typically the number of days from 1/1/2000 till the target release date so that we don't change it ever day.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hey Guys,
If I have created an App.config file in my project, and in that file specified a key and a value. Then coded the following :
string test1 = System.Configuration.ConfigurationSettings.AppSettings["Key1"];
tabPage1.Text = test1;
This sets the Text Property at the top of the Tab Page on start up to what i specified in the config file. Now i want to change the BackColor property of the Tab Page, but i constantly get the following error: Cannot implicitly convert type 'string' to 'System.Drawing.Color' ? Any assistance appreciated.
|
|
|
|
|
You must use the ColorConverter to covert the string to a color, like so:
Color c = this.BackColor;
string color = ConfigurationSettings.AppSettings["BackColor"];
if (color != null)
{
TypeConverter converter = TypeDescriptor.GetConverter(typeof(Color));
try
{
c = (Color)converter.ConvertFromString(color);
}
catch { }
} You can also use the AppSettingsReader , but this is limited to reading types with a Parse method:
AppSettingsReader reader = new AppSettingsReader();
bool b = (bool)reader.GetValue("ShowInTaskbar", typeof(bool)); The first way I outlined is far more extensible and provides support for more types.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks. What if I were to want to set the Alignment property of the TabControl itself ? I've gotten continuous errors with this as well.
|
|
|
|
|
Again, a TypeConverter . Use TypeDescriptor.GetConverter(typeof(TabAlignment)) to get an EnumConverter . You might want to read-up on the TypeConverter in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Cool, i'll read up on the type converter, since im guessing if i want to set any properties that are not strings, this is what i will be doing. Thanks for your help.
|
|
|
|
|
Word of warning - not every type has an associated TypeConverter . Only those types that are attributed with or inherit the ConverterAttribute with a valid TypeConverter (or simulate this through the component model) work. Enums, primatives, and many structs support TypeCoverter s. If you need something more encompassing, then forget about using the <appSettings> section and use a serialization approach, like using XML Serialization (see the System.Xml.Serialization namespace in the .NET Framework sDK). There are many articles here on CodeProject that discuss such an alternative. You could even create your own .config section and use XML Serialization to deserialize more complex types that may or may not have a TypeConverter associated with them. Just search this site for examples.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Can you group sections in a config file, such as
<configuration>
<appsettings>
<add key="LabelColor" value="Red">
<add key="LabelText" value="Test text">
|
|
|
|
|
Sorry, forgot to click the Do not treat <'s as HTML tags
<configuration>
<appsettings>
<add key="LabelColor" value="Red">
|
|
|
|
|
Ok, dont I dont get that one I think you know what I mean. Can i group keys via a tag such as "label" for all keys refering to attributes of a label ?
|
|
|
|
|
Ok, dont I dont get that one I think you know what I mean. Can i group keys via a tag such as "label" for all keys refering to attributes of a label ? Because it keeps giving me a problem with it.
|
|
|
|
|
You might want to encode your < and > with < and > next time.
You can group sections, but they must be accessed as part of a group. You really need to read about .config file. See the IConfigurationSectionHandler for good information and a start. Once you decide to group a section you cannot move it around.
For example, the system.web section is a group and there are many section handlers configured under it (configured in the machine.config file). They are all accessed as "system.web\sectionName". If you change the group they are in, you break the code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I want to display selected items in a listview on another form. for example, I have a form with a listview, three textboxes (lastName, firstName, idNumber), and three buttons (Add, Save, View Form). When I click the view form I want the selected row of items to be displayed on another form that has three textboxes. I have tried many different techniques but none work. Does anyone know how to do this? Any help would be appreciated especially a coded example!!!!
|
|
|
|
|
If these are in the same AppDomain (by default, every process includes one AppDomain), you only need a reference to those TextBox es. It's really a simple object-oriented problem.
So, for one example, when you create your Form with the ListView , pass a reference to the Form with the three TextBox es. Make those TextBox es public or internal (internal is public within an assembly). In the ListView.SelectedIndexChanged , get the ListViewItem and set the TextBox.Text property in the other form using the reference you have to it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Dear forum members,
An object of a managed class (written in C#) is passed to the
clipboard during drag&drop operation. The object has to be
dropped on to a MFC view (written in VC++ .Net).
How do I create/access my object from the COleDataObject
which I get while 'Droping' into a view ?
Is there any other way to do this ?
Thanks in advance.
svkr.
|
|
|
|
|
I already answered your previous post[^]. Like it or not, those are your only two options: exposing a CCW and publishing the interface, or marshaling the data.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I've been using this code without any problems for ages
FolderBrowserDialog Dialog = new FolderBrowserDialog();
Dialog.RootFolder=Environment.SpecialFolder.Personal;
Dialog.ShowDialog();
This stopped working this afternoon just before a demo of my app; There is just a grey window with the create new folder button and OK. Copied into a new app with a button the code works as i would expect.
The only thing i think might have caused it was that i applied a manifest to get the XP look and feel just before i compiled. I can't get the old style browser back now though, i've deleetd the exe and recompiled etc.
this is the manifest i used with the AppName changed to Appname
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestversion="1.0">
<assemblyidentity
version="1.0.0.0"
="" processorarchitecture="X86" name="Microsoft.Winweb.AppName" type="win32">
<description>.NET control deployment tool
<dependency>
<dependentassembly>
<assemblyidentity
type="win32"
="" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorarchitecture="X86" publickeytoken="6595b64144ccf1df" language="*">
anyone has any ideas, i'd be very happy to hear some answers
Russell
|
|
|
|
|
I once experienced the same thing. After long experiments I discovered that this error occurs when the COM threading model for an application is multithreaded apartment (MTA) instead of single-threaded.
<br />
[System.STAThread]<br />
static void Main()<br />
{ <br />
System.Windows.Forms.Application.Run(new MainForm());<br />
}<br />
Maybe you changed that too?
www.troschuetz.de
|
|
|
|
|
Stefan,
You are a complete and utter hero. I did indeed change the threading model of the application, i had never even thought that that could have caused the problem, i'd got myself convinced that it was something to do with that manifest.
Thanks, at least now i know why it's broke i can test some threories
Russ
PS. i just checked the code, and it was just the [System.STAThread] that was missing, excellent fix, thanks
|
|
|
|