You can solve this problem in several ways. For example, you can iherit ToolStripMenuItem class and implement explicit cast (see "explicit" keyword in language reference). Another way is creating generic menu item (e.g. MyMenuItem class) that can create instances of both MenuItem and ToolStripMenuItem hiding itself in its Tag property. And yet another way is to program a converter, that will recursively create MenuItemCollection from ToolStripItemCollection or vice versa, this can be implemented as explicit convesion as suggested in the first paragraph. Hope this helps.
Libor Tinka
Posts
-
Convert MenuStrip to MainMenu -
.net 2005 - win form - manifest - win xp styleI think this should be done programatically. VS 2005 adds these lines in Main() automatically when creating WinForms application: Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false);
-
Problem with FileDropHow to implement Drag&Drop capability of a WinForms application, when we want user to be able to drag and drop files and directories outside the main form through FileDrop? Dragging files from e.g. Windows Explorer to WinForms app is not a problem. But the reverse way is a big problem for me.
-
WinForms: How to override this method?Now it works, thanks. But another few hours have been spoiled on this either.
-
WinForms: How to override this method?I'm trying to make simple class derived from ComboBox that processes some command keys. Here is the code:
#pragma once using namespace System; using namespace System::Windows::Forms; namespace ProjectX { public ref class EnterComboBox : public ComboBox { public: EnterComboBox(void) { } protected: virtual void ComboBox::ProcessCmdKey(Message^% msg, Keys^ k) override { MessageBox::Show("cmdkey"); ComboBox::ProcessCmdKey(&msg, k); } }; }
The compiler outputs error C3254: 'ProjectX::EnterComboBox' : class contains explicit override 'ProcessCmdKey' but does not derive from an interface that contains the function declaration I'm confused. There is no such interface. I've searched whole e-books, forums for the code sample (and more common overrides, like OnPaint, OnResize etc.) and there is no answer how the hell override some method from the Control's base class :mad: -
MDIParent's scroll barsI'll look more carefully, later. There is the solution . But not a managed solution.
-
MDIParent's scroll bars> Why would you want to do this? I'm designing an imaging application. Both Photoshop and Paint Shop PRO does not show scroll bars in their MDI-based environment. > If you try to break the behaviour in any way you run the risk of alienating your users. So in this case and in my opinion - not showing the scroll bars is the "more" standard behaviour. The whole problem should be solved via the MDIClient, but I don't even know where to start.
-
MDIParent's scroll barsHow to avoid MDIParent showing scroll bars whenever the child form exceeds client area? Setting MDIParent.AutoScroll to false doesn't help.
-
Creating setupWe use Inno Setup in our company - it's excellent tool. You can start with ISTool which will guide you through setup script creation (wizard) and then you can advance to your own scripting. Default output is a single .exe file.
-
XP-style folder tree?I spent a several lifetimes by searching how to implement nice folder tree in C#. A tree which looks like that in Windows Explorer. There are several solutions that are complicated, platform-dependent and full of errors. What I need is to implement a tree usable on different platforms only with minimum modifications (it will show "Desktop" and "Network Places" on Win32, but can be simply modified to work well on Linux or Mac with Mono). Of course, there is FolderBrowserDialog but this is a dialog and I need a control that can be docked inside a form and throws several events (directory changed etc.) Any help would be appreciated.
-
Extending large project to Unix (Mono)I'm planning to extend a large .NET project (3 solutions / 20 projects) to Unix through Mono (there should be separate autorun installers for Windows, Linux and Mac OS on a CD for end user). There are many problems. The big one is the use of platform-specific features (registry, API calls) and the other that it is all made with VS 2003 IDE. I know there is not any universal answer for this, but any help or links to information resources would be appreciated - thanks a lot.
-
Local Database vs XMLI saw a few imaging programs, that use local database for storing data about images and thus provide extremely fast image search (wihtout accessing files). I want to implement this: database for faster file search in my C# app, but any SQL tutorial begins with installation of some server tools. However, end user does not have these tools. I also cannot force him to install MS SQL Server, because he may not use Windows (my app should work on other platforms). So I'm confused. Is is possible to use databases as well (in app release, that does not contain huge server tools) or it is better to use some alternative (e.g. store all the data in single XML file)? Thanks a lot, Libor Tinka
-
How to get Image from other Image quicklyThe drawing to separate buffer (doesn't matter how small the buffer is) is slow when working with large images. Drawing small area of 10 by 10 pixels from position [x,y] using graphics.DrawImage(srcImage, new Rectangle(0, 0, 10, 10), x, y, 10, 10) looks fast - try it on 7 megapixel image, it won't be.
-
How to get Image from other Image quicklyI need to divide a very large image (say 5-7 mpx) into smaller pieces (24 bpp Image objects). Algorithm is not a problem, the speed of used GDI+ method is. Using Graphics.DrawImage() is slow, even when no interpolation is done. The problem is not in the count of pieces, but in the size of huge source image. Doesn't matter how large the pieces are, because the long time is taken by the reading of pixels from source. I've thought about using unsafe pixel access, but still hope there's some method for obtaining smaller image from larger one quickly.
-
Accessing local database created in VS 2005 [modified]I have installed and configured MS SQL 2005 Express. Both SQL Server and SQL Server Browser login set to "Local System", Shared Memory, Named Pipes and all the stuff set correctly. If I want to connect to database created in the SQL Server Management Studio, everything is OK, no User ID or Password needed, because of the trusted connection. Then I've added a database in my project and set Windows Authentication in the "Modify Connection...". After running the program, I've got exception number 4060: Cannot open database "AddressBook" requested by the login. The login failed. Login failed for user ''. This is the connection string I've used: SqlConnection myConnection = new SqlConnection( "server=.\\SQLEXPRESS;" + "Trusted_Connection=yes;" + "database=AddressBook;"); Connection test in VS is also OK, only accessing the database (.mdf) programatically using SqlConnection goes wrong. Maybe it's something easy to fix, but I tried books, Google and MSDN without any progress, so I feel desperate from this :(
-
Copy an instanceI'm doing this using the
Clone
method of the object. I think there's no universal mechanism for copying objects, so you need to implement this method by your own. If you are working with more types, it is good to use someICloneable
interface. This is an example:public interface ICloneable { object Clone(); } public class BitmapWithArray : ICloneable { public Bitmap bitmap = null; public int[] array = null; public ushort someValue = 0; public object Clone() { BitmapWithArray obj = new BitmapWithArray(); if (this.bitmap != null) obj.bitmap = (Bitmap)this.bitmap.Clone(); if (this.array != null) obj.array = (int[])this.array.Clone(); obj.someValue = this.someValue; // this is a value type, no copies needed } }
-
Detecting Ctrl + arrow keysI need to distinguish Ctrl and Ctrl+arrow key commands in my app. Using
ProcessCmdMsg
rather thanOnKeyDown
handler allows me to register arrow keys, but when user strikes and holds Ctrl key, there are lot of messages with key code equal to this Control key, bud I'm not able to detect both Ctrl as modifier key and arrow key at the same time. -
Only icon shown in shell context menuInstaller of my app (I'm using Inno Setup) writes some info in registry. I've handled file type associations and even AutoPlay support. The problem is that name of my program is not shown in shell context menu (only icon) and in the "Open in..." dialog. There only icon appears as well. What key should be added/changed to show this information :confused:? Thanks in advance.
-
Crop an image without creating bitmapIs it possible with GDI+ to just crop an image withou creating a new one? I'm working with, say, 5 Mpix photos, so It can be superfluous, to create a cropped 4 Mpix bitmap and then drawing the first one to this. I believe there is something similar to array reallocation applied to images...
-
How to make a setup project which install two applicationsYou can use many installers, but my favourite is Inno Setup. It's free and even for commercial use. If you're not familiar with installers, you can download also IS Tool, which creates your setup project using step wizard. You'll have two items in the "Files" category there. The one is a directory (or just executable) of your app, and the second is the Framework SDK (marked as decompressed into {tmp} (temporary) directory, so its installer will be deleted after whole installation). Now add this file in the "Install Run" category, so that it will be runned after installation of your app. If you want to install it before your application, you have to create a setup component. To make the installation quiet, the SDK installer have to be runned with some parameter ("/q" I think). Hope this helps.