|
Hi,
I have been searching in the web for algorightms or tips about generating diagrams from a database automatically.
I know it's not an easy task, graph theory, exponential algorithms, but I'm searching some starting point, do you know some place / web where I can get that info ( if it has some examples in C# that would be even better ).
Thanks in advance, greetings
Braulio
|
|
|
|
|
Is there an easy method, in c#, to change a form? For instance, in MFC I wrote an application where I had the frame, and then form was shown inside the frame. In this method, I was able to create many forms (CFormView in MFC) and then I could change the forms while keeping the same frame. I'm trying to write this same application using c#, because I find that the controls (windows) are MUCH better! I'm sure it's possible to do this, but how much a pain in the butt is it? Thanks for you help!
|
|
|
|
|
In a very simplistic manner, assume two control classes (or even two instances of the same control class): UserControl1 and UserControl2 , both to be exclusively hosted by MainForm :
public class MainForm : Form
{
private UserControl1 uc1;
private UserControl2 uc2;
private void Next()
{
Controls.Remove(uc1);
Controls.Add(uc2);
}
} Remove one and add the other. This won't create or dispose the instances, just remove them from the collection of child controls for that container (and they can be parented only to one container as with all windows).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I understand your example about creating either multiple controls, or else multiple instances of the same control. My biggest problem now is that I have data that I will load from a file at startup. How is it possible for each of my controls to be able to access this data?
Thanks for your previous help, it was very useful!
|
|
|
|
|
See the documentation for the ConfigurationSettings class. .NET applications typically use .config files (XML files) which have different sections (like AppSettings ), of which you can create your own. Search CodeProject for "configuration settings" as well for more examples and articles.
Since I'm guessing you deleted your other post that I got notification of, I would also suggestion that you skim through the articles in the .NET Framework SDK, under "Programming with the .NET Framework". Reviewing the classes in the System.Windows.Forms namespace would also be beneficial.
Above all, keep in mind there's no magic here. Just like MFC wraps the native Win32 functions for common controls and windows management, so does Windows Forms. In a pinch, you can always override Control.WndProc and handle notification messages like you're probably used in with MFC, but you'll have to P/Invoke (declare external, native functions in C#) native functions like SendMessage , re-create necessary structs (like LVITEM for a ListView or something), and define (if you desire, which is handy) the constants (like private const int WM_HSCROLL = 0x0114 ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How can i convert Links into Images using Rich Text Box in Visual c#.Net
This is Jitendra
|
|
|
|
|
You need to find the images :
Regex r = new Regex("<[^>]*\\n?.*=(\"|')?(?<imog>.*\\.jpg)(\"|')?.*?\\n?[^<]*>");
MatchCollection Matches = r.Matches(rtb.Text);
and then replace them with an image
foreach (Match m in Matches)
{
string imageName = m.Groups["imog"].Value;
Image img = Image.FromFile(imageName);
rtb.SelectionStart = m.Index;
rtb.SelectionLength = m.Length;
Clipboard.SetDataObject(img);
rtb.Paste();
}
Warning though this code does not work properly. Problem one is the regular expression which I found off the web doesn't handle img tags very well.
Problem two is find the SelectionStart once you've started replacing the text.
I know this sucks but i thought it would give you a start.
HTH
Circumstances have overtaken man. His old languages are not sufficient to describe what is happening, and what is about to happen. To think in terms of a millennium or such tame concepts as the 'eleventh hour' is ridiculous.
Better that he should realize that he is in an era which might be accurately described as the 'eighth
day of the week'. Idries Shah
|
|
|
|
|
Thanks .
This is Jitendra
|
|
|
|
|
How can i convert Links into Images using Rich Text Box
This is Jitendra
|
|
|
|
|
Everytime I open up a C# project and click build, a new assembly gets created even if none of the source files and references are modified. However, once I build once, then for that session, any further build will not create a new assembly (unless I change something of course). How to make the first build after opening the project to also not build if nothing has changed?
|
|
|
|
|
Opening VS.NET treats the project like its new/modified. There's no documented way to change this that I've ever seen.
If you're concerned about versioning problems, first don't use automatic version incrementing in larger projects with multiple assemblies. Not only does it create problems like this, but it makes deployment and tracking a pain in the arse. You can also facilitate better builds by using project references for projects in your solution instead of assembly references if you're not already. This keep dependencies in sync and keeps the build configuration constant for all projects.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the info.
The problem I have is that I have a library project which gets referenced (yes, project reference) by some exe projects. Everytime I compile one exe project, the library project also gets compiled too. Isn't it better to use assembly references in this case? That way, I only build the library project whenever I change it?
|
|
|
|
|
I wouldn't say it's "better", but you sure could. Just make sure that when switching between build configurations you update the assembly reference (if you use pre-proc conditions to change any of the code, for example).
The nice thing about project references is that is how VS.NET sets up dependencies (it's odd you can't do this manually like with VC++ projects, though). If your library project changes (and I understand that it will appear to at startup and that's annoying), your apps should recompile it if the recompile is necessary. It will only get built once until the library project changes again (or you restart VS.NET).
Again, it's up to you and really doesn't matter, but this is just something to consider.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm making the switch from MFC to C#, or at least attempting, so here's an opportunity for a couple of you to get points for posting an answer to what is probably an easy question (keep looking for my name, more will be coming.) At any rate, I want to be able to use a DataGrid object on my form. I have read through countless articles, but I'm just not getting it. All I want is 8 columns, each of a primitive type (int, string, double). I just want the grid to be blank, with the first row showing, then when the user puts information into the first row, the next row shows up, etc. Is this really that hard to do? I'm using Visual Studios .NET, fyi.
Please only point me to an article if it answers my question...so far all of the articles I've found just bind the grid to a pre-existing data source...that's not what I have here. Thanks a ton...and for those using c# for a while...don't bash me too hard!
|
|
|
|
|
Just create a new DataTable, add a few columns of the appropriate type, and set the grid data source to the new table You have to make sure the grid allows new:
DataTable t = new DataTable();
t.TableName = "test";
t.Columns.AddRange(
new DataColumn[] {
new DataColumn("one", typeof(string)),
new DataColumn("two", typeof(int)),
new DataColumn("three", typeof(DateTime)),
new DataColumn("four", typeof(string)),
new DataColumn("five", typeof(bool)),
new DataColumn("six", typeof(double))
});
dataGrid1.DataSource = t;
The above code in my small test app was in the constructor of a form after the InitializeComponent() call. I created a C# Windows Forms project, added a DataGrid, then added the above code.
It should be a simple starting point.
|
|
|
|
|
The code that uses pre-existing data sources is what you need. The DataGrid - without overriding practically everything about it - is a data-bound control. If you use it for data entry, you must get the data from it somehow. You can do this by retrieving the DataSource value, which can be anything that implements IList or IListSource (like a DataSet , ArrayList , etc.).
Nothing says that data has to contain data initially, though. The easiest example is to use a DataSet , which you can - through code or by creating a typed DataSet - define a table and columns. In your DataGrid , set the DataSource to the empty DataSet instance, the DataMember to the name of the DataTable within the DataSet and you're basically done. You'll find that you'll have more control over the layout if you use the DataGrid.TableStyles property to add a corresponding DataGridTableStyle with various (8 in your case) DataGridColumnStyle s. The documentation in the .NET Framework SDK for any one of those 3 aforementioned properties and classes will have an example (same example, IIRC).
You could also use an ArrayList or any other type of list with a list of classes that define properties and bind your DataGrid in the same way. The problem is this can be difficult if you have no initial data since the DataGrid wouldn't know how to construct your data source.
When the DataGrid is bound - even to an empty data source - rows can be added like you want. With a data source, the DataGrid can't add rows to anything because it has nothing to add them to. Give it a data source (again, I recommend a DataSet ) and now it has something to modify since it's just a view on the data source.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi,
I want to ask, how can I get mouse position in realtime except getting it inside MouseEvent Handler?
The Idea is, I have one context menu, after I clicked the menu button, I want to show one dialog at the mouse location immediately.
Thanks for help
|
|
|
|
|
You can get the mouse position at any time - in screen coordinates - using the static Control.MousePosition method which returns a Point . To convert these coordinates to form coordinates, call PointToClient with the Point on the control that you want to the relative coordinates for (relative to the upper-left corner).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
In my app a user chooses an icon. I want to save that icon to a file. However, no matter what I try, the image is saved incorrectly. I did some searching and found that there may be some troubles with saving the alpha channel info. I am no expert on images so I have no idea.
All I want to do is save the icon to a file. I tried
<br />
using (StreamWriter swI = new StreamWriter(Application.StartupPath + "/TestI.ico")) <br />
{<br />
ico.Save(swI.BaseStream);<br />
}<br />
However, the icon is saved in poor quality and when I load it, it looks pretty bad.
Can someone please help me? I just want to save an icon and be able to load it when I need it.
P.S. Is it possible for me to save multiple icons in one file and extract the icons one at a time?
Thanx for the help,
-Flack
|
|
|
|
|
A few things - don't use a StreamWriter , you may run into encoding problems. An icon is a binary file, so just use something simple like a FileStream .
Also, instead of Application.StartupPath + "/TestI.ico" , use Path.Combine(Application.StartupPath, "TestI.ico") , which properly combines the directories and/or filename with the correct directory separator. It may have worked this time, but it usually won't depending on the circumstances.
Finally to the real problem. The icon support in the .NET stinks. Icon files contain a header section that describes the resolution and addresses of indexed bitmaps (has palettes) within the file. Because of an apparent but in the System.Drawing classes, the 32-bit icon (which contains the per-pixel alpha channel) is not well preserved (and sometimes not at all).
The best way is to P/Invoke the various icon functions from the Windows Shell APIs, like SHCreateFileExtractIcon , which uses the COM interface IExtractIcon , which is pretty simple to declare as a managed interface (be sure to use the GuidAttribute with the right interface ID (IID)).
As far as extracting various resolutions from an icon file with multiple bitmaps, this is exactly what Windows does with methods like that from above and all the lower-level icon functions like GetIcon . Most of the time, the small and large icon handles (HICON ) are returned at once with the appropriate resolution. In order to get 32-bit icons with the native APIs, you must use an application manifest to bind to Common Controls 6, which is described in my article Windows XP Visual Styles for Windows Forms[^]. If you're using .NET 1.1 or higher, you can also call Application.EnableVisualStyles before Application.Run , but be sure to read the documentation for a few quirks (like calling Application.DoEvents in between the two to avoid common problems).
If you want complete control over the icons, how they save, and which icons are extract, read about Icons in Win32[^]. All those structs can be create in .NET easily enough, so long as you use the appropriate StructLayoutAttribute since some structs have a pack size, IIRC, of 2.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Does anyone have an idea on how to capture scrollbar events from a ListView control?
|
|
|
|
|
Extend it and override WndProc . Handle the WM_HSCROLL (0x0114) and WM_VSCROLL (0x0115) notification messages. See the Platform SDK for the possible WPARAM and LPARAM values.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I running a service with no dialogs. I like to put an icon in the tray to show that the process is running. I don't know where to begin.
Thanks.
|
|
|
|
|
If this is running as a true Windows Service (Services Control Panel), then you would normally write a second app that communicates with the service you wrote and controls the icon in the Tray.
RageInTheMachine9532
|
|
|
|
|
other than that u could just insert a notifyicon component from the toolbox :P
i jsut havent figured out how to add a context menu to it!
|
|
|
|
|