|
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!
|
|
|
|
|
I got a file which is an assembly file (managed code).
Now how do I find out programatically from unmanaged code?
TIA
Promise only what you can do. And then deliver more than what you promised. This signature was created by "Code Project Quoter".
|
|
|
|
|
Kant wrote:
I got a file which is an assembly file (managed code).
Now how do I find out programatically from unmanaged code?
Find out what?
RageInTheMachine9532
|
|
|
|
|
Dave Kreskowiak wrote:
Find out what?
My bad.
Find out programatically(from unmanaged), Is that file is an assembly file or not.
Promise only what you can do. And then deliver more than what you promised. This signature was created by "Code Project Quoter".
|
|
|
|
|
See my article, Shell Extensions for .NET Assemblies[^], a handy overlay icon handler that distinguishes between the two. The source is included.
There's a single bit that is different in the PE/COFF header of the executable. You load and map the DLL or EXE as a data file and traverse several virtual tables to find the address of this bit, then you check it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
There's a single bit that is different in the PE/COFF header of the executable
Now how the HELL did you figure that one out??
Damn geniuses...year younger than me, already got an MVP...I don't have an MVP title...work my fingers to the bone, day in, day out, for bent pennies...
|
|
|
|
|
I strive to know everything.
I read an article a long time back in MSDN Magazine from executable master Matt Pietrek, the guy who wrote dumpbin.exe. In this article he briefly mentioned about this bit but nothing more. Using concepts from his article i dug into the PE/COFF header format and wrote the code to find that bit and check it. Learned a heck of a lot about the PE/COFF in the process, which is really what I was after in the first place.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|