|
Hello,
I'm trying to write my own custom toolbar from scratch.
Now I've a problem: I created a class named coolToolBarButton which contains information about the button. Those buttons are grouped into a coolToolBarButtonCollection-Class.
I tried to add buttons to the toolbar via the designer, but it doesn't work. I clicked on the porperty field and the "coolToolBarButton Collection Editor" appeared. I was able to add some buttons, but then I clicked on the OK-Button and the buttons weren't added to the collection!
What's wrong?
Here's the code:
public class coolToolBarButton
{
private Image m_Image;
[DefaultValue(null),
System.ComponentModel.RefreshProperties(RefreshProperties.Repaint)]
public Image Image
{
get { return m_Image; }
set
{
m_Image = value;
}
}
}
public class coolToolBarButtonCollection : CollectionBase
{
public int Add(coolToolBarButton Button)
{
return List.Add(Button);
}
public void Insert(int index,coolToolBarButton Button)
{
List.Insert(index, Button);
}
public void Remove(coolToolBarButton Button)
{
List.Remove(Button);
}
public bool Contains(coolToolBarButton Button)
{
return List.Contains(Button);
}
public int IndexOf(coolToolBarButton Button)
{
return List.IndexOf(Button);
}
public void CopyTo(coolToolBarButton[] array, int index)
{
List.CopyTo(array, index);
}
public coolToolBarButton this[int index]
{
get { return (coolToolBarButton)List[index]; }
set { List[index] = value; }
}
}
///
/// Summary description for coolToolBar
///
public class coolToolBar : System.Windows.Forms.Control
{
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
private coolToolBarButtonCollection m_ButtonCollection;
public coolToolBarButtonCollection Buttons
{
get { return m_ButtonCollection; }
set
{
m_ButtonCollection = value;
}
}
.......
|
|
|
|
|
When you change the images collection, you have to Invalidate the control which will force it to repaint. I got extremely frustrated with the same problem!
|
|
|
|
|
Do you mean they don't show up on the toolbar, or that they aren't serialized to code? If you mean the latter case, you must attribute your collection property with DesignerSerializationVisibility(DesignerSerializatioVisibility.Content) (uses the DesignerSerializationVisibilityAttribute ) so that it serializes the collection to your source file. You can also override this behavior by attributing your toolbar class with a custom designer using the DesignerAttribute .
See Enhancing Design-Time Support[^] in the .NET Framework SDK for more information on the .NET component model and design-time capabilities.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It works now! Very good!
But there's another problem: I placed my custom toolbar on the form and added some buttons. If I remove the toolbar, the single buttons don't get removed from the code!
|
|
|
|
|
This is my code:
[DesignTimeVisible(false)]
public class coolToolBarButton : Component
{
private Image m_Image;
[DefaultValue(null),
System.ComponentModel.RefreshProperties(RefreshProperties.Repaint)]
public Image Image
{
get { return m_Image; }
set
{
m_Image = value;
}
}
}
public class coolToolBarButtonCollection : CollectionBase
{
public int Add(coolToolBarButton Button)
{
return List.Add(Button);
}
public void AddRange(coolToolBarButton[] Buttons)
{
for(int i=0;i<buttons.length;++i)
list.add(buttons[i]);
="" }=""
="" public="" void="" insert(int="" index,cooltoolbarbutton="" button)
="" {
="" list.insert(index,="" button);
="" }
="" remove(cooltoolbarbutton="" list.remove(button);
="" bool="" contains(cooltoolbarbutton="" return="" list.contains(button);
="" int="" indexof(cooltoolbarbutton="" list.indexof(button);
="" copyto(cooltoolbarbutton[]="" array,="" index)
="" list.copyto(array,="" index);
="" cooltoolbarbutton="" this[int="" index]
="" get="" {="" (cooltoolbarbutton)list[index];="" set="" list[index]="value;" }
="" <summary="">
/// Summary description for coolToolBar
///
public class coolToolBar : System.Windows.Forms.Control
{
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
private coolToolBarButtonCollection m_ButtonCollection;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public coolToolBarButtonCollection Buttons
{
get { return m_ButtonCollection; }
set
{
m_ButtonCollection = value;
}
}
public coolToolBar()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
m_ButtonCollection=new coolToolBarButtonCollection();
SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.ResizeRedraw |
ControlStyles.StandardDoubleClick |
ControlStyles.UserMouse |
ControlStyles.StandardClick |
ControlStyles.SupportsTransparentBackColor,
true);
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region Component Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
protected override void OnPaint(PaintEventArgs pe)
{
// TODO: Add custom paint code here
// Calling the base class OnPaint
base.OnPaint(pe);
}
}
|
|
|
|
|
I'm building an asp.net app with c# to load data from different file resources, validate it and push it into a SQL Server db. I've handled Word interop so I can pull in data from pre-defined Word documents, validate and load it. I've worked with CSV's and have no problem there.
The issue I'm having is XML, or rather XSD.
I have an XSD which I want to use to validate data imported from XML. I've tried the XSD.exe tool but it just doesn't seem to generate an accurate typed dataset, basically not all datatables I'd expect defined, are defined. Can I use an XSD file at runtime to validate XML imported using ReadXML, and if not, how else can I do this?
Any thoughts appreciated, all avenues explored...
Rhys
"When one burns one's bridges, what a very nice fire it makes" -- Dylan Thomas
"As to marriage or celibacy, let a man take the course he will. He will be sure to repent" -- Socrates
"Doh!" -- Homer Simpson
|
|
|
|
|
try using the XMLValidatingReader
|
|
|
|
|
I have a client program that talks to an IBM mainframe and recieves 64bit unsigned integers(STCK) that represent date-time values. I need to convert these to native DateTime format for use in my c# code. Anyone have or know of any conversion routines available for this purpose. If not I'll have to write my own. Thanks.
dzs
|
|
|
|
|
DateTime stores time information in ticks, or 100 ns (.0001 milliseconds). It also uses an epoch (start date) of January 1st, 0001 AD at 12:00:00 midnight (00:00:00). Using that information, you'll have to convert your STCK (most likely stored in milliseconds, as date/time types are) accordingly. There is nothing in the .NET FCL to assist you with that. You will then, of course, have to find out both the unit and epoch of the STCK data type.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
My goal is to have a control which will mimic Windows Explorer while viewing in thumbnail mode. Is there one which exisits in the .net framework?
---
I want to create a digital image manager to allow me to batch rename, rotate, resize etc...
Does something like this exist?
|
|
|
|
|
|
Thanks for the suggestion. Do you have any places I could look to see like how a Textbox is rendered to the screen so I can make my own?
|
|
|
|
|
Something I have noticed and not sure if it is a bug in the developer or what. But here is the scenerio.
1) Make webform
2) Place a Datagrid control on it
3) Add and oledbdataadapter and the dataset
4) Since The database will be pointing to the local harddrive by default I have to change the connection string. Like so:
string datapath = Server.MapPath("/bin/csharp.mdb");
this.oleDbConnection1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ datapath;
This works fine but here is the catch.
If i change anything at all on the datagrid like for instance an event like delete
or change a property then all the sudden I no longer have an oleDbConnection at all.
It completely wipes out the code that I typed and doing a search for jet turns up nothing.
Same applies if I add an insert cause by default the datagrid control doesn't have a templated insert. I add one manually
this.DataGrid1.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.insertme);
If i change anything on the datagrid via its properties after making that code addition the line of code will be wiped out. And yes I save the code before modification.
Any ideas? Gets annoying after a while. I typed the strings about 4 times after it wiped them clean and i go heck with this and made a text file where i could cut and paste.
Win32newb
"Programming is like sex, make one mistake and you have to support it for a long time"
|
|
|
|
|
Changing anything the designer creates and uses is likely to cause such problems. If you want to continue to use the designer, I recommend that you click the Advanced [...] button under the Configuration category in the PropertyGrid while your connection is selected and add an entry for the connection string to the appSettings section of your Web.config file. This is more robust anyway. If you decide, for example, to move your .mdb out of your web application, you can easily change the connection string to reflect that. Since you're using the OLE DB client for ADO.NET, you could even change the connection string to use a different provider (provided that all your ADO.NET code would work with a different one, which is usually fine for most OLE DB providers).
The designer shouldn't complain and croak now.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
report viwer sql reporting services in code?
|
|
|
|
|
I don't have a lot of experience with SQL 2000 RS yet (we'll be looking more into it in the future when we redesign quite a bit of our codebase), but I did watch the MSDN TV video, Developing Applications Using SQL Server 2000 Reporting Services[^], and I believe this was discussed. IIRC, you can pass parameters via GET or POST data, as well as set parameters using the object model (the managed classes and their members).
More information should be available in the RS documentation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
yes i got it using the url which was easy but took some finding. I think sql reporting services very good i was getting too many bugs from crystal reports and gave up. but sql is very clean. I do need to get more info on the object way of doing it through the reporting web service. I would like to emigrate my family to the USA and good links on finding a sponser for wrok?
|
|
|
|
|
Hi,
I have a main application (Main), from which i can launch two different applications (App1 or App2). I each case i am minimizing the main (Main) application to trash. But on exiting the applications (App1) or (App2), is there any way to restore the window of the main application without double clicking on the Trash icon. I have a requirement to do so. Can somebody help me on this?
Harihara Subramanian
|
|
|
|
|
The other applications will need a reference to the switchboard. You'll either need to use .NET Remoting in order to show/hide forms or use Windows messaging. At least, those two would be the easiest ways. You could create some protocol and use a socket connection, but .NET Remoting wraps all that rather nicely.
So, if the switchboard registered a WKO (well-known object), the other applications could call remote methods on that WKO. The implementation of that object (having a reference to the main Form ) could call Show and Hide when appropriate, or change the WindowState to minimize it to the task bar (not trash, unless you're talking about some specific region within your application) or restore it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks a lot for the immediate reply. I am a little confused as the main application is a .NET application and for the rest, one writeen in VB and the other in VC++. As the intention behind this usecase is to switch to only one of the application at any instance of time.
There is an executable called 'Interoperator' written in VB to which the main application passes instruction like the context information and the application code (App1 or App2).
I have minimized the main application to the task bar(used the ShowinTaskbar property and set it to false), however i do not know how i can send a message back to the main application window to restore it once the applications (App1 or App2) are closed.
private void App1_Click(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
Trash.Visible = true;
}
Can this scenario be handled without having to do anything with modifying the applications as such by a generic design pattern (Switch board)that acts more like a window manipulator?
Harihara Subramanian
|
|
|
|
|
You didn't mention the other applications weren't .NET applications. Since this is the C# forum - a language targeting the CLR - one can only assume. You should be more specific next time.
You could call FindWindowEx , passing NULL as the first param to use the desktop window's HWND . Find your switchboard by title or classname. That will return you the HWND for your application (an IntPtr in managed code), which you can pass to the ShowWindow API.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks again. ShowWindow API displays the Window only when it is present in the Task bar. It is not able to launch the window that is not present in the Task bar.
The following code snippet is what i used.
[DllImport("user32.dll")]
public static extern long ShowWindow(Int32 hwnd, Int32 ncmdShow);
private void App1_Exit(object sender, System.EventArgs e)
{
p = System.Diagnostics.Process.GetProcessesByName("Framework");
ShowWindow(p[0].MainWindowHandle.ToInt32(),1);
}
However in the main application while launching the other applications i used the below mentioned code
private void App1_Launch(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
both the API FindWindowEx and the usage of process to find the handle returns a 0 (zero) when the window is not shown in the task bar. Kindly help me in this regard.
Harihara Subramanian
|
|
|
|
|
First of all, both parameters of ShowWindow should be IntPtr s. These are native ints, which are processor-dependent - just like the IntPtr (32 bits on a 32-bit CPU/OS and 64 bits on a 64-bit CPU/OS).
Also,don't blindly access p[0] . If, for some reason, the process wasn't found an IndexOutOfRangeException or NullReferenceException (depending on what GetProcessesByName returns when a process isn't found) would be thrown.
Getting the Process is no problem. The reason is the MainWindowHandle is returning IntPtr.Zero is because it doesn't currently have one - the main window is invisible. Either don't remove it from the task bar (via ShowInTaskbar ) or try something else.
You could use a mutex and signal it. Any application can use them. C/C++ and .NET have support already (C/C++ through APIs, obviously, and .NET in the System.Threading namespace - which actually uses the same C/C++ APIs internally). With VB (by which I assume you mean VB6, since VB.NET uses the same .NET FCL as C# with only a slightly different syntax) you'd have to declare these native functions.
When the switchboard starts, you create two mutexes (one for each app, or you could use one with a counter) but don't request initial access. When an applicatio starts, you wait on the mutex (to be signaled). When the other applciations exit, you signal the mutex and the switchboard could make itself visible. You could do this in a loop if you wanted, if a user can switch back and forth.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have an idea, but not skilled enough to implement in code. It goes like this, the main application which is a .NET assembly will override the Wndproc method. Tha applications will send a user defined message to indicate that they are done while dieing. The Wndproc will handle this message and take appropriate action.
Will this work? Kindly help me.
Harihara Subramanian
|
|
|
|
|
Simple override WndProc and define a const with your message value like so:
private const int WM_USER = 0x0400;
private const int WM_USER_SHOW = WM_USER + 1;
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_USER_SHOW)
{
ShowInTaskbar = true;
Show();
}
} Your other applications should send this message (using SendMessage ) using the same message value (0x0401). The problem is that to send the message to the application, you still need a valid Window Handle. Why, then, did I post the code above? To show you what it would look like if you had a valid Window Handle (HWND ) for your application.
You might instead consider using the NotifyIcon component to "minimize" your application to the system tray ("systray" - where the clock is and possibly other icons). It would still maintain a valid Window handle so that messages to your systray icon are handled by your application. See the documentation for the NotifyIcon component in the .NET Framework SDK for more information. There's also several articles here on CodeProject about it and some alternatives.
Microsoft MVP, Visual C#
My Articles
|
|
|
|