RichTextEditBox and LinkLabel winforms c# - c#

I am using a windows forms RichTextEditBox. I load a RTF file into the control. I then set the following code.
int indexToText = rteb.Find("here");
LinkLabel link = new LinkLabel();
link.Text = "here";
link.LinkBehavior = LinkBehavior.AlwaysUnderline;
link.LinkClicked += new
LinkLabelLinkClickedEventHandler(this.link_LinkClicked);
LinkLabel.Link data = new LinkLabel.Link();
data.LinkData = "Sending Report Results to Multiple Recipients.pdf";
link.Links.Add(data);
link.AutoSize = true;
link.Location = rteb.GetPositionFromCharIndex(indexToText);
link.Height = 40;
link.Width = 60;
link.ForeColor = Color.Blue;
rteb.Controls.Add(link);
when the app is run, the word "here" is in blue, but I don't get an underline and when I try clicking on the word, my click event doesn't fire off. What am I missing here?

To set an underlined link area in LinkLabel you should set LinkArea property to the range which should be shown as link, for example:
LinkLabel link = new LinkLabel();
link.Text = "here";
link.LinkArea = new LinkArea(0, link.Text.Length);
link.LinkBehavior = LinkBehavior.AlwaysUnderline;

Related

i cant insert section break in aspose.word after add header

after insert header in aspose.word I want insert BreackNewPage
but
Exception occurred when insert section break in aspose.word for .Net
my Code Is in here:
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
Shape shape = builder.InsertImage(dataDir);
shape.Height = builder.PageSetup.PageHeight - 200;
shape.Width = builder.PageSetup.PageWidth - 50;
shape.WrapType = WrapType.None;
shape.BehindText = true;
shape.RelativeHorizontalPositionRelativeHorizontalPosition.Page;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
shape.VerticalAlignment = VerticalAlignment.Center;
builder.InsertBreak(BreakType.SectionBreakNewPage);
Your cursor needs to be inside the "main Story" to be able to insert the requested break. Please see following code:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
Shape shape = builder.InsertImage(MyDir + #"aspose.words.jpg");
shape.Height = builder.PageSetup.PageHeight - 200;
shape.Width = builder.PageSetup.PageWidth - 50;
shape.WrapType = WrapType.None;
shape.BehindText = true;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
shape.VerticalAlignment = VerticalAlignment.Center;
builder.MoveToDocumentEnd();
builder.InsertBreak(BreakType.SectionBreakNewPage);
doc.Save(MyDir + #"17.11.docx");
I work with Aspose as Developer Evangelist.
You can use a simple function provided by aspose.word as
Document doc = new Document();
DocumentBuilder documentBuilder= new DocumentBuilder(doc);
documentBuilder.MoveToDocumentEnd(); //moving cursor to end of page.
documentBuilder.InsertBreak(BreakType.SectionBreakNewPage); // creating new page.
documentBuilder.PageSetup.ClearFormatting(); //clear formatting.

WPF: The font will not change on a printed FlowDocument

I am trying to print the contents of a rich-text box. I do that in the following way:
Obtain a TextRange from the FlowDocument.
Create a new FlowDocument with a smaller font using the TextRange.
Send this new FlowDocument to the printer.
My problem, is that the font doesn't seem to change. I would like it to go down to size 8. Instead, it remains at a fixed size. Here is my code:
private void button_Print_Click(object sender, RoutedEventArgs e)
{
IDocumentPaginatorSource ps = null;
FlowDocument fd = new FlowDocument();
PrintDialog pd = new PrintDialog();
Paragraph pg = new Paragraph();
Style style = new Style(typeof(Paragraph));
Run r = null;
string text = string.Empty;
// get the text
text = new TextRange(
this.richTextBox_Info.Document.ContentStart,
this.richTextBox_Info.Document.ContentEnd).Text;
// configure the style of the flow document
style.Setters.Add(new Setter(Block.MarginProperty, new Thickness(0)));
fd.Resources.Add(typeof(Paragraph), style);
// style the paragraph
pg.LineHeight = 0;
pg.LineStackingStrategy = LineStackingStrategy.BlockLineHeight;
pg.FontFamily = new FontFamily("Courier New");
pg.TextAlignment = TextAlignment.Left;
pg.FontSize = 8;
// create the paragraph
r = new Run(text);
r.FontFamily = new FontFamily("Courier New");
r.FontSize = 8;
pg.Inlines.Add(r);
// add the paragraph to the document
fd.Blocks.Add(pg);
ps = fd;
// format the page
fd.PagePadding = new Thickness(50);
fd.ColumnGap = 0;
fd.ColumnWidth = pd.PrintableAreaWidth;
// print the document
if (pd.ShowDialog().Value == true)
{
pd.PrintDocument(ps.DocumentPaginator, "Information Box");
}
}
I would like to add that, changing the font works just fine for the flow-document when it is inside of the rich-text box. However, when I am doing it programmatically (as shown above) I run into problems.
I try your code and found when I remove this line and then change the r.FontSize to 50, it seems work.
pg.LineHeight = 0;

ASP.NET - Change label color and conc with string

I create a label and set his TEXT color to red. I use ForeColor property but with him not working :(
This is my UI:
This is my label code:
Label reqF = new Label();
reqF.Text = "*";
reqF.ForeColor = System.Drawing.Color.Red;
reqF.CssClass = "formvalidation";
reqF.Font.Size = 15; // 15px
This is my string code:
TableHeaderCell header1 = new TableHeaderCell();
header1.Text = "Destination" + reqF.Text; <----------- My label
tRow0.Cells.Add(header1);
In this line
header1.Text = "Destination" + reqF.Text;
you add only the text (*) to the destination, not the full div with the style on.
The easiest (and faster) way is to direct add the style online as:
header1.Text = "Destination <span style=\"color=red\">*</span>" ;
You are only using text of the control, not the whole control with styling. Your code should actually look something like that:
TableHeaderCell header1 = new TableHeaderCell();
LiteralControl literal = new LiteralControl();
literal.Text = "Destination";
header1.Controls.Add(literal);
header1.Controls.Add(reqF);
tRow0.Cells.Add(header1);
Note that here Literal control is used to insert the Description string, and then the whole Label with the * is being inserted.

Add textbox via dynamic imagebutton in a panel

I have a problem I seem to stumble over all the time, I have a Drop Down box and you can select a number which creates x number of textboxes with images buttons its for a survey it the image buttons are used to create "Sub-Answers" so they can have answers to answers so my question is I need to when they hit the image button to create a textbox under the orginal textbox here is the code.
for (Int32 i = 1; i <= NumberOfAnwsers; i++)
{
Literal l1 = new Literal();
l1.Text = "<tr><td>Answer " + i + " text.</td><td>";
TextBox tb = new TextBox();
tb.ID = "TextBoxAnswer" + i;
tb.EnableViewState = false;
tb.Width = 300;
Literal l3 = new Literal();
l3.Text = "</td><td>";
Literal l2 = new Literal();
l2.Text = "</td></tr>";
RadColorPicker CPI = new RadColorPicker();
CPI.PaletteModes = PaletteModes.WebPalette;
CPI.ID = "RadColorPicker" + i;
CPI.ShowIcon = true;
CPI.SelectedColor = System.Drawing.Color.Black;
ImageButton IBVideo = new ImageButton();
IBVideo.ID = "IBVideo" + i;
IBVideo.ImageUrl = "/images/video-icon.jpg";
IBVideo.ToolTip = "Add Video";
IBVideo.Height = 20;
IBVideo.Width = 20;
ImageButton IBAdd = new ImageButton();
IBAdd.ID = "IBAdd" + i;
IBAdd.ImageUrl = "/images/add-icon.png";
IBAdd.ToolTip = "Add Sub-Answers";
//IBAdd.OnClientClick = "showDialog(" + i + ");return false;";
IBAdd.Height = 20;
IBAdd.Width = 20;
//Add Textbox
PanelAnswersToQuestions.Controls.Add(l1);
PanelAnswersToQuestions.Controls.Add(tb);
PanelAnswersToQuestions.Controls.Add(l3);
PanelAnswersToQuestions.Controls.Add(CPI);
PanelAnswersToQuestions.Controls.Add(IBVideo);
PanelAnswersToQuestions.Controls.Add(IBAdd);
PanelAnswersToQuestions.Controls.Add(l2);
}
As you can see I just add controls to the panel, I need to know when that ImageBUtton is hit I can add a Textbox and in this case it could be more then just one textbox to it.
I hope this is clear but for some reason I dont think it is ... sorry.
I have added a radwindow and poping that up sending the Data to the partent via javascript the which created a new problem for me, I can not in javascript seem to find the dynamicly created hiddenfield
function OnClientClose(radWindow) {
var oWnd = $find("<%=RadWindowAddSubAnswer.ClientID%>");
var SubAnswerValues = oWnd.get_contentFrame().contentWindow.document.forms(0).HiddenFieldSubAnswers.value;
alert(SubAnswerValues);
var AnswerID = oWnd.get_contentFrame().contentWindow.document.forms(0).HiddenFieldAnswerID.value;
alert(AnswerID);
var HiddenName = "HiddenFieldSubAnswers" + AnswerID;
alert(HiddenName);
document.getElementById(HiddenName).value = SubAnswerValues;
$get("DivSubAnswers" + AnswerID).innerHTML = SubAnswerValues;
}
The "document.getElementById(HiddenName).value = SubAnswerValues;" seems to never be found, I also tried $get(HiddenName).value = SubAnswerValues; that does not seem to work either both come back as null as for the code behind its:
HiddenField HFSubAnswers = new HiddenField();
HFSubAnswers.ID = "HiddenFieldSubAnswers" + i;
HFSubAnswers.Value = "0";
Im not sure if I got your question right but if you need to dynamically add controls on a Page here is what I can say.
Before adding your control I guess you need to find the control where you need to add it on, Add the control then assign the properties.
PlaceHolder myPlaceHolder = (PlaceHolder)Page.FindControl("PlaceHolder1");
myPlaceHolder.Controls.Add(myButton);
myButton.Text = "Hello World";
For a more detailed expalnation go here http://anyrest.wordpress.com/2010/04/06/dynamically-removing-controls-in-a-parent-page-from-a-child-control/

Dynamically filling ListView with an image and a string

I would like to fill my ListView with do aligned elements, a little icon (either a confirm mark or a cross) and a string which contains the result of a question (Right / Wrong, that's why icon).
daInserire = new ListViewItem();
daInserire.Foreground = new SolidColorBrush(Colors.DarkGreen);
daInserire.Content = "Giusto: "+ straniero.Text + " = " + vocItaliano[current];
daInserire.HorizontalContentAlignment = HorizontalAlignment.Center;
daInserire.FontSize = 18;
//...
listViewConInfo.Items.Add(daInserire);
This works perfectly, I'd like to add before the string, on the same line an image.
Looks like you're using WPF, so you'll need to create a StackPanel for your Content property and add the Image and a Label to that StackPanel.
ListView lV = new listView();
ListViewItem Item = new ListViewItem();
WrapPanel wrap = new WrapPanel();
Image image = new image();
image.Source = <<yourSource>>;
Label label = new Label();
label.Content = "W/E you want";
wrap.Children.Add(image);
wrap.Children.Add(label);
Item.Content = wrap;
lV.Items.Add(Item);

Categories

Resources