|
Hi,
I want to display some text on a tabpage given that some of the text is linkable. How do I do this?
I tried using both label and linklabel to display them, but the thing is that I don't get any of these label/linklabel text displayed at all except the last linklabel text. What have I done wrong?
int lab_tab_idx = 0;
int linklab_tab_idx = 0;
int y = 0;
foreach (DataRow dr in text.Rows)
{
string text = Convert.ToString(dr[1]);
/* e.g. {hyperlink FANTASTIC PHONICS} is based on national research
which shows that the best outcomes are achieved with
{hyperlink SYSTEMATIC} instruction, using {hyperlink GUIDED
READERS} which are sequential and gently graded. */
string[] newtext = text.Split('{', '}');
int i = 0;
int x = 3;
System.Windows.Forms.Label label = new System.Windows.Forms.Label();
LinkLabel linklabel = new LinkLabel();
while (i < newtext.Length)
{
string tmp = newtext[i];
if (tmp.StartsWith("hyperlink "))
{
tabPage1.Controls.Add(linklabel);
linklabel.AutoSize = true;
linklabel.Location = new System.Drawing.Point(x, y);
linklabel.Name = "linklabel" + linklab_tab_idx;
linklabel.TabIndex = linklab_tab_idx;
linklabel.TabStop = true;
linklabel.Text = tmp.Replace("hyperlink ", "");
x = x + linklabel.Text.Length * 6;
linklab_tab_idx++;
}
else
{
tabPage1.Controls.Add(label);
label.AutoSize = true;
label.Location = new System.Drawing.Point(x, y);
label.Name = "label" + lab_tab_idx;
label.TabIndex = lab_tab_idx;
label.TabStop = true;
label.Text = tmp;
x = x + label.Text.Length * 6;
lab_tab_idx++;
}
i++;
}
y = y + 20;
}
Also, how do I calculate the location of the next label as the text string is dynamic?
Thanks
printscreen12345
|
|
|
|
|
Your calculations seem right but you are reusing the same Label/LinkLabel again and again instead of creating a new one in each iteration:
while (i < newtext.Length)
{
string tmp = newtext[i];
if (tmp.StartsWith("hyperlink "))
{
LinkLabel linklabel = new LinkLabel();
tabPage1.Controls.Add(linklabel);
linklabel.AutoSize = true;
linklabel.Location = new System.Drawing.Point(x, y);
linklabel.Name = "linklabel" + linklab_tab_idx;
linklabel.TabIndex = linklab_tab_idx;
linklabel.TabStop = true;
linklabel.Text = tmp.Replace("hyperlink ", "");
x = x + linklabel.Text.Length * 6;
linklab_tab_idx++;
}
else
{
Label label = new Label();
tabPage1.Controls.Add(label);
label.AutoSize = true;
label.Location = new System.Drawing.Point(x, y);
label.Name = "label" + lab_tab_idx;
label.TabIndex = lab_tab_idx;
label.TabStop = true;
label.Text = tmp;
x = x + label.Text.Length * 6;
lab_tab_idx++;
}
i++;
}
|
|
|
|
|
Thanks for your reply. It works now when I create the label in each iteration.
Some of the labels seem to have overlapped one another and some of them are quite further away from one another. How do I solve this problem?
Is there any other effective way to display text like this? It is quite slow.
Also, why is the text display from bottom up instead of the normal top-to-bottom?
Thanks again.
printscreen12345
|
|
|
|
|
Thats probably because the length og the characters of the gont you are using isn't always the same. Either use a gont where all characters have a fixed length (like Courier New) or make the following changes:
x = x + linklabel.Width;
x = x + label.Width;
As you have set AutoSize to true this will ensure that the next label is set right next to the previous one. It still might be that there is some space in between but definitely no overlapping.
|
|
|
|
|
Great! But the text is displayed from bottom-right back up to top-left. How do I change this display order?
printscreen12345
|
|
|
|
|
I shortly tested the code and it seems to be in the order I would have suspected. How are you getting the values into the text DataTable? Are you sure its in the correct order in there? If you have a DataGrid where this table is bound to and the grid is somehow sorted or columns are rearranged via column styles this might lead to what you are seeing because the DataTable won't be reordered the way the grid is.
So please describe a bit of the surroundings. Maybe then I can help you.
|
|
|
|
|
I guess I have not made it clear enough. When all label text are displayed, they are in correct order. But the last label (which is from the last row of the datatable) is displayed first in the bottom-right corner instead of the first label being displayed first at the top-left corner. Why does this happen?
I tried using flowlayoutpanel but I'm not quite sure how to use this.
|
|
|
|
|
Hmm... I don't know. My small test data displayed fine. You could try debugging through each label creation to verifiy that they are created in the correct order...
|
|
|
|
|
If you are using .NET Framework 2.0, take a look at the FlowLayoutPanel, which dynamically lays out its contents horizontally or vertically. This could spare you the whole calculation part.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
I want to receive message of yahoo messenger by a C# program that I wrote but I don't know. Cam you help me? I sent message to chat window of yahoo messenger by APIs.
This is image for my request:
http://dangkimienphi.googlepages.com/sendmessageeng
Phong
|
|
|
|
|
Hi all.
I'm looking for someway that I can set a registration code or license key.
Something in the concept of the app generating a code on their side, they call and give it to us and then we use that code to generate another code on our side. Then they must enter that code provided from us.
Somehow that code must be stored and every time the app is started it must check if the code is still within the valid period.
Any ideas?
Thanx
He who laughs last is a bit on the slow side
|
|
|
|
|
i'm using datagrid called (ctgrid) right to left not provided in it ... how can i add this properity to this control ..in Vc++ i solv this problem by using api function called getwindowlong and setwindow long but in c# i don't know how can i use api's so if any one can help me i will be glad ..thanks alot..
aloka basha
|
|
|
|
|
alokabasha wrote: but in c# i don't know how can i use api's
Research PInvoke. Maybe this[^] will help
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
thank u very much for ur help i found there many things can help me .. i will try to use it.. Do u know datagrid control simply can be used as (Right to left) thaANK u again
|
|
|
|
|
I have a TreeView control inside a TabControl. Im adding my items from a collection.
foreach (LogicStatementLine line in ift.Triggers)<br />
{<br />
newNode = new TreeNode(ift.GetObjectName(line), 10, 10);<br />
node.Nodes.Add(newNode);<br />
newNode.Tag = line;<br />
}
I have set the ShowNodeTooltips to false on the TreeView control. Yet Im still getting them when the text extends beyond the viewable area. Is there anyway to turn them off completely?
|
|
|
|
|
i have this problem (Thread is running or terminated; it cannot restart.)
and i search for solution but what i was read about that {thread which has died cannot be resuscitated}, so how can i make the aborted thread start again ?
|
|
|
|
|
|
You cannot restart a thread which has completed (normally or abnormally). You have to either create a new thread or use a thread pool.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
thanks..
i just make new thread within my loop
|
|
|
|
|
How can i simulate Mouse Events so that any control who wired on to event and has an event handler will be called without clicking the mouse physically.
Another Simulation, simulating MouseMove on the screen to an object and clicking it.
|
|
|
|
|
u can try
MouseEventArgs E=new MouseEventArgs(MouseButtons.Left,1,3,3,3);
form1_MouseDown(this,E);
this will call forms mouse down event with out acctually clicking mouse.
rahul
|
|
|
|
|
Is there a way to query AD for the computer name the user is logged onto based on their user name?
I work at a Help Desk and we're constantly asking for their computer name so we can remote in with some 3rd party software. It seems there should be a way to query AD based on their user name and get the name of the machine they're currently logged onto.
I'm looking to make a simple console app, similar to "net user jdoe1 /do" or something along those lines. Any ideas?
|
|
|
|
|
Might be more of a framework question.
It is a design-time question.
So I am interfacing with an object (to be written by someone else), which executes requests asynchornously on a worker thread. I am interested in an failures that may occur in the execution of my request. How can he propogate exceptions to my original thread of execution?
Thanks
NIK
|
|
|
|
|
Put all the worker code in a wrapper method that looks something like:
try
{
DoProcessing();
}
catch(Exception e)
{
//Invoke some method/event on the original thread here
}
catch
{
//Invoke some method/event here as well; even though C# doesn't allow it, there can be exceptions that don't have objects
}
|
|
|
|
|