|
|
It you'd like an easy way to determine if something is an assembly in Windows Explorer (I know this isn't what you're looking for, but you might like it anyway), see my free shell extension on this site - with source included - Shell Extensions for .NET Assemblies[^]. A couple column providers are also provided to custom a detailed view in Windows Explorer.
There's also code in there that shows how you determine if an executable is an assembly or not by navigating through the virtual tables in the PE/COFF header. There is a managed way to do this as well, but I can't seem to find it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The folllowing code I create a Listview with 550 Columns.
Now when you scroll to the end, the headers arent diaplyed correctly, but the data is OK. It appears there is a limit on the size the Columnn Headers can draw in.
Has anybody else has this problem?
Is there a work around for it?
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication6
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListView listView1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.listView1 = new System.Windows.Forms.ListView();
this.SuspendLayout();
//
// listView1
//
this.listView1.Location = new System.Drawing.Point(16, 32);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(256, 208);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.listView1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
for(int i =0; i < 550; i++)
{
System.Windows.Forms.ColumnHeader colHead = new System.Windows.Forms.ColumnHeader();
colHead.Text = "TQQ" + i;
listView1.Columns.Add(colHead);
}
ListViewItem item1 = new ListViewItem("Test");
for(int i =0; i < 550; i++)
{
item1.SubItems.Add(i.ToString());
}
listView1.Items.Add(item1);
}
}
}
|
|
|
|
|
Nothing is documented in the Header common control documentation as being a hard limit, but with so many columns I would venture a guess that memory consumption is likely the problem.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
I want to assign special keys (like F2,F3...) to operation.
Like the accelerate table that is in MFC.
Tell me if there is a way to do that without catching the key down.
I know i can do it with windows API (Hooks) but i want mor elegant way.
Thanks,
Adam
|
|
|
|
|
A good way using global application shortcuts is to implement the IMessageFilter interface and add it using Application.AddMessageFilter . This implementation could either hard-code shortcut keys (handling the notification messages such as WM_KEYDOWN (0x0100)) or use a map file so that a user can define their own shortcuts if such functionality is desirable. Make sure your implementation is efficient, however, since all messages throughout your application will be routed through this interface (it hooks the message pump).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi All,
To me Reflection.Emit and OpCodes are a cryptic way to generate code. I'm wondering if the System.CodeDom.Compiler namespace provides equivalent functionality. In particular it seems possible to use CSharpCodeProvider to compile C# code to assemblies.
Is this true, and if so what are the disadvantages and advantages of Emit and Opcodes vs CSharpCodeProvider? Also if my application uses CSharpCodeProvider and code compilation will it be deployable on all systems supporting the .net platform?
Thanks,
Ben
|
|
|
|
|
The CSharpCodeProvider is a Microsoft extension to the CLI so it may not be supported in, say, Mono.
As far as the differences between the two, however, Reflection.Emit should be available on all platforms. Another difference is that you can use Reflection.Emit without generating source files to compile using a CodeDomProvider. They are both ways of generating assemblies at runtime, it's really more of a question about which suits your needs.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I have a Mobile App running on PocketPc 2003 OS. My connection to a Sql database is not consistent. What design should I go with in order to store data locally and when connection is made download data to database ? Should I use maybe web services or MSMQ? Any ideas please?
Im leaning more toward MSMQ since their is a trigger mechanism to test for connection to other computer. What do you think?
Thanks,
JJ
|
|
|
|
|
Um, did you read my post to your previous, similar question? Use SQLCE and replicate with the MSDE or SQL Server database. It's simple.
See Designing "Sometimes Off-line" Microsoft .NET Compact Framework Applications[^] for an article about this.
Basically, IIRC there's a little install you run on the server that enables replication with a SQLCE database. When your device syncs with the server (or your desktop, whichever) the database is replicated. No code to write in such a case and you can take advantage of pretty much all the replication features, such as not firing certain triggers during replication.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have created several ASP.NET server controls, but this is my first attempt at a control for Windows Forms. I need to build a control that has no visual component (for example, like an ImageList control).
When I inherit from Control, it brings along a ton of properties and methods that I don't need or want (i.e. backcolor, font, anchor).
What should I inherit from in order to create a control with no design time or visual properties? Just the properties and methods I dictate?
-Todd Davis (toddhd@hotmail.com)
|
|
|
|
|
Are you sure you want to create a control? Todd Davis wrote:
no design time or visual properties? Just the properties and methods I dictate?
Sounds like you just want to define your own class.
class ToddsClass{
public int ToddsInteger;
public int ToddsMethod(int iFactor){
return(iFactor*this.ToddsInteger);
}
public ToddsClass(){
this.ToddsInteger=1;
}
}
Or am I missing something?
Bill
|
|
|
|
|
Yup, you are right. I figured that out shortly after posting this. I had defined the class as a source code file, but we needed it to be a *.dll, and I got hung up on choosing Windows Forms Library from the new project wizard. I instead chose Class library, and now life is good...
thanks! Never code when it is past your bedtime...
-Todd Davis (toddhd@hotmail.com)
|
|
|
|
|
If you want a component like the ImageList , however, that can interact with the designer, extend the Component class.
Also, this has absolutely nothing to do with what kind of project you create. You are supposed to add classes to that and understand what's in the source file. A Windows Forms Application can contain all the same things a Windows Control Library can, and even an ASP.NET Web Application can, too, though a Windows Forms class won't do much good there. The difference is how the assemblies are built, whether they are self executing or loadable (among a few other differences in the PE/COFF header and where everything is located, etc.).
Todd Davis wrote:
Never code when it is past your bedtime...
...or before reading the documentation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I want to set single click and double click events of mouse programatically in C#.For example i have mouse x=30,y=40;on 1024*786 resolution I want to single or double click at this point programatically(user does not press the actual mouse button).In other words i want to simulate the mouse.
please give me sample code or tell me some api's and how to use these api's in c#.
mughalali
|
|
|
|
|
Mughalali,
Someone smarter than me will have to tell you how to do that if, indeed, you can. I suggest trying to accomplish whatever you need to accomplish in other ways. If you need to give the focus to a particular control or cause an event on another control to fire, there are easier ways to do that stuff.
Without knowing more about why you want to do this, I can't really offer any more concrete advice.
Bill
|
|
|
|
|
You can use the SendInput native API (btw, "API" just means Application Programming Interface, which all your .NET classes and members are, too; "API" is not tied to a particular framework or platform).
Anyway, thanks to http://pinvoke.net[^] I shouldn't have to go into details anymore for this API, since the Wiki page even includes an example. See http://pinvoke.net/default.aspx/user32.SendInput[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
In addition, if you want to use coordinates relative to your control, see the PointToScreen method inheritted from the Control class that will return screen coordinates for the given client coordinates.
Also, they re-define the VK enumeration. You don't need to do this. The Keys enumeration in the System.Windows.Forms namespace contains the same defs.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am currently using a listbox to list strings in my app. This is convenient for handling a single double click event and processing the event depending on which item was clicked. The problem i am having is that only the listbox forecolor is allowed to be modified, not the items forecolor. If an item is currently selected (in this case the media file is playing) i would like the color to be different. I want the user to be able to double click an item to play. Originally I populated a blank panel with labels so that I could change the colors, however, creating event handlers for each one is not the right approach. Is there a way to change the color of individual items in a list box; OR is there a better way to manage a single event for multiple controls and still get information from the control that was clicked.
thanks in advance
John C
|
|
|
|
|
A couple of things...hopefully they can help:
1) You can do what you want to do with a listbox. You just need to make it into a user-drawn listbox. In a nutshell: set the DrawMode property to one of the OwnerDrawn options:
<br />
this.listBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;<br />
Then handle the DrawItem event. I've attached a simple program below that draws the selected list item in CadetBlue. It's a little more involved than just setting a color but it's also very powerfull. There are a number of interesting examples in the articles here at codeproject...just snoop around.
2) You can manage a single event on multiple objects very easily: just create event handlers that call the same function. For example:
label1.Click += new System.EventHandler(this.GenericClickHandler);
label2.Click += new System.EventHandler(this.GenericClickHandler);
...
private void GenericClickHandler(object sender, System.EventArgs e){
}
Here's the code I promised:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace ListBoxText
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox listBox1;
private System.ComponentModel.Container components = null;
int i=-1;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
this.listBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.listBox1.Items.AddRange(new object[] {
"one",
"two",
"three",
"four",
"five"});
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(120, 199);
this.listBox1.TabIndex = 0;
this.listBox1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.listBox1_DrawItem);
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(120, 197);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.listBox1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void listBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
if (e.Index == this.i)
{
e.Graphics.FillRectangle(Brushes.CadetBlue,e.Bounds);
}
else
{
e.Graphics.FillRectangle(Brushes.White ,e.Bounds);
}
e.Graphics.DrawString (this.listBox1.Items[e.Index].ToString(),new System.Drawing.Font("Comic Sans", 8),Brushes.Black, e.Bounds);
}
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.i = this.listBox1.SelectedIndex;
this.listBox1.Invalidate ();
}
private void label1_Click(object sender, System.EventArgs e)
{
}
}
}
|
|
|
|
|
Didn't we have this conversation a long time ago, and I told you that players like Windows Media Player and RealOne actually use the List-View common control, which is encapsulated by the ListView control in the .NET FCL? It already supports all this behavior. Read the class documentation in the .NET Framework SDK to learn more.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I don't think we've had this conversation... This is the first time I've asked this since I finally got around to coding. Thanks for the reply.
|
|
|
|
|
My apologies, then. I did have this conversation with someone quite some time ago.
Anyway, the ListView is probably what you want. If you're thinking of something like Windows Media Player or RealOne uses (keeps it's selection after loosing focus), then you definitely want the ListView . Hooking up events to either is a cinche, but the ListView does have an ItemClick event making it a little easier. Also, you can store sub-items (like you'd see for the file size, modified date, and file type in Windows Explorer which also uses the List-View common control) which might be a good place to keep the filename, or you could always use the ListViewItem.Tag property which could be anything you want (but won't display).
If you set ListView.HideSelection to false , then when the control loses focus the item is still highlighted (though in a different color defined by the user's display preferences). All the highlighting is done for you already, too. Like I said, WMP, RealOne, Windows Explorer, and many, many other applications use this control probably more than any other complex control.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Did you notice the toolbar below the posting window? Why don't you try using it, and you'll see the supported HTML tags you can use, as well as emoticons below the formatting toolbar. If you don't see it, try using Internet Explorer.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I would just like to say, that this is not good. Why on earth is it so hard to implement support for mozilla?
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|