|
This is a repost of [^] on QA Sept. 22. The question was upvoted, and several detailed suggestions presented.
"Last year I went fishing with Salvador Dali. He was using a dotted
line. He caught every other fish." Steven Wright
|
|
|
|
|
I don't know how to Insert image on ricktextbox. Can you help me?
|
|
|
|
|
I needed that functionality not so long ago, and was able to get it up and running, with a lot of help from Google.
It is quite complex, and beyond the scope of a forum message. Here is the gist of it:
- a RichTextBox basically displays whatever is in an RTF document (which can be created using an app such as WordPad, or MS Word; or can be constructed programmatically by obeying the RTF specification).
- AFAIK the only way to have an image in an RTF, is by embedding all the image data using a MetaFile; there are two metafile formats, WMF and EMF, one is easier to construct, the other is what is needed eventually.
- there isn't an all-managed solution; you would need to call some native Windows functions (GdipEmfToWmfBits, DeleteEnhMetaFile), which requires P/Invoke.
The dataflow is like so:
Image -> Graphics -> Metafile(EMF) -> Metafile(WMF) -> RTFdocument
If you feel up to it, you now have a number of essential keywords. Good luck.
|
|
|
|
|
Luc Pattyn wrote: Image -> Graphics -> Metafile(EMF) -> Metafile(WMF) -> RTFdocument
Bloody hell - I'm glad I gave up trying to supply a richtext requirement in Silverlight, I can guarantee if I had I would have ended up dealing with this issue and I choked on the simple formatted text requirement.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I had exactly this requirement and can confirm that what Luc outlines here is the only way (at least, the only way I found) to make it work. You can embed an EMF in a metafile, according to the spec, but neither the RichText nor Word will actually display it.
|
|
|
|
|
BobJanova wrote: but neither the RichText nor Word will actually display it.
Now that is not correct; RichtTextBox, WordPad and Word happily display my programmatically generated RTF tables and images.
Of special interest to me is WordPad being always present in a Windows environment, with pretty much constant functionality over the years, and able to display a lot of things that it doesn't allow you to create interactively; all of this makes it a rather good report viewer, my reports then being RTF files.
|
|
|
|
|
They will happily display an embedded EMF image? I couldn't make them do that, even though according to the spec it is allowed. I had to do what I understood from your first post, use some P/Invoke hackery to get a WMF and embed that instead.
Tables ... ah, tables. It's possible to write a perfectly valid (according to the spec) table that WordPad/RichTextBox won't eat, too. In particular you can't protect a row from leaking formatting information with {\b ... }, you have to use \b ... \b0. And it doesn't respect cell wrapping or auto-size requests, either.
|
|
|
|
|
As I said, I convert the image to a WMF (that is what I use the native GdipEmfToWmfBits for); EMF is just an intermediate step. It works well for images, it works great for charts, assuming you start from a MetaFile, not a Bitmap.
And I tend to use tables as an "easy" way to position and size the images!
|
|
|
|
|
Yep, that's what I had to do. I think you misread my first post in this subthread – it is embedding EMFs that is allowed under the spec but no reader will actually display the result.
My application was producing statistical reports so we actually wanted tables for tabular output, and some of them have enough columns that getting them all onto the paper at a reasonable size involved some serious hand-crafting of column widths.
|
|
|
|
|
OK, I see what you mean; yes it has to be WMF, hence GdipEmfToWmfBits and practicing some P/Invoke.
|
|
|
|
|
We have a need to provide some functionality in the form of a LDAP Listener within our services product. I do not know much about this area, so I am looking for ideas
Our objectives are to:
1) Listen for LDAP Queries from a third party
2) Determine what the query is
We do not have direct access to Active Directory, but instead must make calls to a web service that does the LDAP query to AD on our behalf, hence the need to determine what the query is
3) Carry out the query (to the web service) and provide an LDAP Response to the third party
We would like to do this in code (VB.Net/C#)
|
|
|
|
|
Hi,
I am using sorting feature in multiple columns in a gridview. My gridview sorting is like this:
protected void gView_Sorting(object sender, GridViewSortEventArgs e)
{
try
{
if (this.ParentPortlet.PortletViewState["direction"].ToString() == "")
{
this.ParentPortlet.PortletViewState["direction"] = " ASC";
}
else if (this.ParentPortlet.PortletViewState["direction"].ToString() == " ASC")
{
this.ParentPortlet.PortletViewState["direction"] = " DESC";
}
else if (this.ParentPortlet.PortletViewState["direction"].ToString() == " DESC")
{
this.ParentPortlet.PortletViewState["direction"] = " ASC";
}
}
catch
{
this.ParentPortlet.PortletViewState["direction"] = " DESC";
}
getData(e.SortExpression.ToString(), this.ParentPortlet.PortletViewState["direction"].ToString());
}
I have four columns in the gridview (Name, Date, Location, Cell) and all these columns are sortable. so If i click name, it sorts in desc order and again if i click it, it will sort in asc order which is great. Similar with the other fields. But my problem is If I click the Name, it will sort in desc order. Now If i click Date, it will sort in asc order. Again If I click the Name, it will sort in desc order. Is there any way we can put these sortings independent to each column. Like, If I click Name, it should sort in desc order. Now If I click date, it should sort in desc order. Now again, If i click Name, it should sort in asc order.
Any ideas?
suchita
|
|
|
|
|
Using a Hashtable, or similar structure, to store the sort direction based on column is about the only way to get this done I can think of at the moment
No comment
modified 25-Oct-11 14:45pm.
|
|
|
|
|
Can you point me to any example on this, please?
suchita
|
|
|
|
|
|
Hi,
I don't know about GridView. However I can tell you about WinForms' DataGridView:
1.
if you provide no code at all, it will sort itself as it should; each column remembers its sort direction, and will toggle it every time you hit the column header without having hit another column header.
2.
It does not have a Sorting event (i.e. no pre-Sort), it does have a Sorted event (post-Sort).
BTW: GridViewSortingEventArgs.SortDirection tells you how the GridView is going to be sorted. Either it is column-specific or unique for the entire GridView, I don't know (and MSDN seems not to be clear on this). If it is column-specific, you should just use it; if it is a single bool covering all columns, you need to replace it by one bool per column, a HashTable could help you do that.
|
|
|
|
|
I have no idea how do we use hashtable for each column event for gridview..
suchita
|
|
|
|
|
you want to hold one boolean flag for every column, but have them structured, not just a bunch of loose flags. There are several ways to do that.
One way is by holding an array of four bools, one for each column, and use the column number as the array index.
A more elastic approach would rely on a HashTable or better yet a Dictionary<string,bool> where the key could be the column header text (they have to be unique!), and the value is the bool itself. That way you can find the bool for a column by feeding the column header text to the HashTable/Dictionary.
BTW: you could use the Column itself as the key, however that may or may not be any easier.
PS: if you're new to HashTable/Dictionary you should read up on those classes.
|
|
|
|
|
Hi all,
I want to create a setup of my c# application with some merge modules adding in to it and without using visual studio deployment kit.
Is there any other third party software which can do it.For example like InstallShield.
Thanks in advance.
|
|
|
|
|
InstallShield. Wix. InnoSetup. They all can manage this - it's a fairly fundamental requirement of installer applications.
|
|
|
|
|
I written this test code that places a form onto tab pages. Each button click creates a new tabbed page with two colored forms on it. I've gotten some suprise that this is in fact possible. Nevertheless, I need to find a way to have each form run in its own thread. Does anybody have any ideas how this might be done?
Form1 has a button and a tabControl
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
Form3 form3 = new Form3();
tabControl1.TabPages.Add("tabPage" + (tabControl1.TabPages.Count - 1).ToString());
form2.TopLevel = false;
form2.BackColor = Color.Blue;
tabControl1.TabPages[tabControl1.TabPages.Count - 1].Controls.Add(form2);
form3.TopLevel = false;
form3.BackColor = Color.Red;
tabControl1.TabPages[tabControl1.TabPages.Count - 1].Controls.Add(form3);
form2.Show();
form3.Show();
}
|
|
|
|
|
Why do you think you need that?
In WinForms all GUI elements (Controls) should be created by the main thread, and that thread only then is allowed to touch them, so what you are after is nearly impossible. In a normal application, all event handlers are swift, so there should be no reason to reorganize things in a way Windows doesn't like. If one of the handlers (say a Button_Click handler) needs to execute long winding code, then that code itself should be executed by another thread (and not touch any Controls); a BackGroundWorker often comes in handy here.
You may want to read this article of mine[^].
BTW: I don't know why you want to add a Form to a TabPage, adding a UserControl is easier and often is all one needs; and using DockStyle.Fill is often what I want.
|
|
|
|
|
You might say for the challenge of it, doing what seems impossible can be fun, but really because I need this level of functionality. I have actually accomplished the task. Here's how I did it.
Main Form - Click Button to add a new Form2 to a tab control
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
tabControl1.TabPages.Add("tabPage" + (tabControl1.TabPages.Count - 1).ToString());
form2.TopLevel = false;
form2.BackColor = Color.Blue;
tabControl1.TabPages[tabControl1.TabPages.Count - 1].Controls.Add(form2);
form2.Show();
}
Form2 - Has a top panel strip with a button, that when pressed opens a child form (Form3) in its own thread, within the area of second panel that sits below the top panel.
public partial class Form2 : Form
{
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
public Form2()
{
InitializeComponent();
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
ThreadStart ts = new ThreadStart(StartUiThread);
Thread t = new Thread(ts);
t.Start();
}
public void StartUiThread()
{
var frm3 = new Form3();
IntPtr intptr = new IntPtr();
this.UIThread(delegate { intptr = this.panel2.Handle; });
SetParent(frm3.Handle, intptr);
Application.Run(frm3);
}
}
public partial class Form3 : Torbo.DockableForm
{
public Form3()
{
InitializeComponent();
}
private void Form3_Load(object sender, EventArgs e)
{
label1.Text = "Thread: " + Thread.CurrentThread.ManagedThreadId.ToString();
}
}
static public void UIThread(this ATE_nonATE control, Action code)
{
if (control.InvokeRequired)
{
control.BeginInvoke(code);
return;
}
code.Invoke();
}
Two myths are busted here. You can put forms onto other controls like a tabControl and it is possible to create threaded child forms.
|
|
|
|
|
You can, but the question still remains why you should. Anything that's going on in a background thread must (by definition, since you can't update the UI directly from it) be business logic and therefore shouldn't be in the same class as the 'view' (in view/model terms), i,e, the form. Running two message loops will cause surprising things to happen, e.g. message boxes spawned on one thread aren't in the same modal UI stack as forms in another, so they don't stop operation. I think the same applies to other modal dialogs (i.e. called with ShowDialog), and the Z-order rules (topmost forms etc).
|
|
|
|
|
There has never been a 'myth' that you could not put a WinForm inside other Container objects' Controls Collection ... as long as you set the TopLevel property to 'false.
Yes, you are 'free' to create things as weird as a Form inside a TextBox:
Form2 f2 = new Form2();
f2.TopLevel = false;
textBox1.Controls.Add(f2);
f2.Show();
And, ready the bell, book, and candle, you can even do this:
Form2 f2 = new Form2();
f2.TopLevel = false;
f2.Parent = textBox1;
f2.Show();
But the interesting question is: why you would want to use a Form inside another container in the first place.
I stand ready for you to illuminate me on that, and I'd be happy to learn my assumptions are incorrect !
A WinForm is not a "light-weight object." And UserControls and Panels ... and later .NET additions like FlowLayoutPanel and TableLayoutPanel ... at least Panel and UserControl being much lighter-weight than a Form ? ... are really the "designated hitters" for use as containers of Controls within Forms, or other container controls.
A UserControl, or a Panel, can actually have size co-ordinates larger than the effective screen resolution: a Form cannot. Forms come with a baggage of adorner buttons (Max, Min, ControlBox), and various properties and methods, you will probably not need when one is used inside another Control.
In case someone trots out old the old war-horse, MDI architecture on this thread as a case for Forms inside a Form: rest-in-peace, MDI. Your gargoylish time came and went, and, for your time, you were, perhaps like Quasimodo in "The Hunchback of Notre Dame," necessary to ring some bells, but, sorry, we got new-fangled carillons these days that look a lot smarter.
We got 'TopMost' to make floating windows now, say halleleujah !
I don't pretend to understand what you are doing with threading in your code, but it looks like an interesting experiment. My one question would be that if you are using the standard Program.cs method of launching the app by creating an instance of a primary Form: when the user closes that primary Form, which normally auto-shuts-down all other created Forms ... and you've got this child-form which you voodoo'd to make run in a separate thread: what happens to that own-thread child-form ? Does the thread terminate properly ? Is the child-form window closed as usual ?
I hope I don't sound critical here: I have a history of learning/exploring technology by 'tormenting' structure, and 'pushing the envelope' to see what happens, myself
One of my favorite experiments, years ago, was a collection of sticky-notes (individual Forms) that ... in reponse to a certain key-stroke combination on any of the sticky-forms ... 'collapsed' into a single Form with a TabControl, where all the Controls in each sticky-Form appeared in separate TabPages, each titled with the name of the sticky-Form. But ... I remained pure ... and the TabPages were not violated by Forms
And then, you typed the same keystroke combination on this Main Form and it was made invisible, and all the sticky-Forms were 'exploded,' shown again, restored to their last location: fun !
By the way, there are some interesting things done with multiple AppDomains in a WinForm project in Chris Sells' book on WinForms from Addison-Wesley, on which I was a technical-editorial consultant ... I think they might interest you.
best, Bill
"Last year I went fishing with Salvador Dali. He was using a dotted
line. He caught every other fish." Steven Wright
|
|
|
|
|