I want to insert text from TextBox in a word document using c# and spire.dll tools, but when I using code FillEffects not worked same this code
textBox.Format.FillEfects.Gradient.Color1 = Color.Red;
textBox.Format.FillEfects.Gradient.Color2 = Color.Yellow;
textBox.Format.FillEfects.Gradient.ShadingStyle = GradientShadingStyle.DiagonalUp;
The code is correct and my program is build correct, but it not make any changes for textBox and if I want to fill effect with picture it not worked else Like this code
textBox.Format.FillEfects.Picture = pictureBox1.Image;
I Attach To you My small project to see why this code not worked
Okay after trying to fix this for a few hours i figured it out. I have slightly re-coded your textbox but don't worry. I added comments. I worked hard on this one. The answer though, was quite simple. I have never used Spire so I had to learn as I went.
//Creates gradient
Spire.Doc.BackgroundGradient myGradient = new BackgroundGradient();
myGradient.Color1 = Color.Red;
myGradient.Color2 = Color.Yellow;
myGradient.ShadingStyle = GradientShadingStyle.DiagonalUp;
myGradient.ShadingVariant = GradientShadingVariant.ShadingDown;
//Insert TextBox
Paragraph paragraph1 = section.AddParagraph();
Spire.Doc.Fields.TextBox textBox = paragraph1.AppendTextBox(200, 100);
textBox.Format.LineColor = Color.DeepSkyBlue;
textBox.Format.LineWidth = 3.5F;
textBox.Format.LineStyle = TextBoxLineStyle.Double;
//Sets the gradient you made
textBox.Format.FillEfects.Gradient = myGradient;
//Sets the textbox to USE the gradient
textBox.Format.FillEfects.Type = BackgroundType.Gradient;
Please add below code to your program before setting the textBox fill effect.
textBox.Format.FillEfects.Type = BackgroundType.Gradient;
E-iceblue Support team.
Related
I'm trying to insert links into my RichTextBox. I do not mean setting DetectUrls to true, I want alternate text. What I have so far seems to be working mostly fine.. I'm using much of the code from this solution. But my issue is that there is some trailing whitespace in the LinkLabel that end up cutting off some of the text that follows it.
Here is what I have so far:
private void Form1_Load(object sender, EventArgs e)
{
//My text with a placeholder for the link: %link1%
//NOTE: I can see the leading '>' fine, but the '<' gets hidden by the link label, and it looks like a space between the link text and "Near..."
richTextBox1.Text = "This has a link here:>%link1%<Near the middle.";
LinkLabel link1 = new LinkLabel();
//link1.Margin = new Padding(0); //Doesn't help
//link1.Padding = new Padding(0); //Default is already 0
//What I want to see in my hyperlink
link1.Text = "My_Link_Text";
link1.Font = richTextBox1.Font;
link1.LinkColor = Color.DodgerBlue;
link1.LinkClicked += Link_LinkClicked;
LinkLabel.Link data = new LinkLabel.Link();
//For now, just test with google.com...
data.LinkData = #"http://google.com";
link1.Links.Add(data);
link1.AutoSize = true;
link1.Location = this.richTextBox1.GetPositionFromCharIndex(richTextBox1.Text.IndexOf("%link1%"));
richTextBox1.Controls.Add(link1);
//Replace the placeholder with the text I want to see so that the link gets placed over this text
richTextBox1.Text = richTextBox1.Text.Replace("%link1%", link1.Text);
//Attempt to manually shrink the link by a few pixels (doesn't work)
//NOTE: Turns out this cuts back on the link test, but leave the trailing space :(
//Size s = new Size(link1.Width, link1.Height); //Remember the autosized size (it did the "hard" work)
//link1.AutoSize = false; //Turn off autosize
//link1.Width = s.Width - 5;
//link1.Height = s.Height;
}
The LinkClicked event, just for the curious. Nothing special.
private void Link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
}
Here is what I see, for reference (notice the missing '<'):
The reason for using a RichTextBox is that I also plan on adding formatting when I am finished (ability for text to be bold, colored, etc.). I'm basically 2 hours away from scrapping the RichTextBox and drawing everything manually onto a panel and handling click position...
I am trying to change the font color of a word document style using office.interop but the color doesn't change. Any idea?
I tried it in two different ways.
The 1st is by trying to change the color of heading style in ms word:
here's some code:
Application appWord=new Application();
Document doc=new Document();
ListGallery gallery=appWord.ListGalleries[WdListGalleryType.wdNumberGallery];
ListTemplate template =gallery.ListTemplates[4];
Style style=doc.ListTemplate[2];
style.LinkToListTemplate(template,1);
style.Font.ColorIndex=WdColorIndex.WdBlack;//doesn't work
doc.saveAs2(path);
The 2nd way is by trying to set the color of the range or selection after inserting the file into ms doc:
Paragraph p3 = wordDocument.Paragraphs.Add();
Range r3 = p3.Range;
//r3.Font.TextColor = WdColor.wdColorBlack;
var filename=String.Format("{0}Resources/TEST1.html", AppDomain.CurrentDomain.BaseDirectory);
String newString=System.IO.File.ReadAllText(filename).Replace("</body>","<p>1</p></body>");
System.IO.File.WriteAllText(filename, newString);
appWord.Selection.Font.ColorIndex = WdColorIndex.wdBrightGreen;
r3.InsertFile(filename);
//r3.Font.olorIndex = WdColorIndex.wdBrightGreen;
edit:
here is the solution:
(document.Styles[WdBuiltinStyle.wdStyleHeading2]).Font.ColorIndex = WdColorIndex.wdBlack;
thanks
you have written in your program
style.Font.ColorIndex=WdColorIndex=WdBlack;//doesn't work
Correct the above line as
style.Font.ColorIndex=WdColorIndex.WdBlack; // this will work
edit:
here is the solution:
(document.Styles[WdBuiltinStyle.wdStyleHeading2]).Font.ColorIndex = WdColorIndex.wdBlack;
thanks
I have a list of Accounts with some properties which are saved in a database.
On my Window I´m going to show the Username from the Account list
for (int i = 0; i < liste.Count; i++)
{
Label l = new Label();
l.Height = 30;
l.HorizontalAlignment = HorizontalAlignment.Left;
l.Content = liste[i].Username + "\n";
l.MouseDown += new MouseButtonEventHandler(Selectuser);
l.HorizontalContentAlignment = HorizontalAlignment.Left;
stack.Children.Add(l); // stackpanel in the xaml
SetKnownImageAcc(Convert.ToInt32( liste[i].AccAId)); // add a picture near the username
}
So I have now I MouseButton Event on every label I created but when I click on one of the usernames I the code behind I only can get the content of the Label so I don't know which Account it is exactly.
Sure i can make a loop to check liste[i].Username = this.content
But my Problem then is that i have more accounts and for example I have 2 accounts one facebook and one google but they have the same username how do I know now in the codebehind which account it is where I clicked
A friend said to me that I should try it with databinding but i´m new to coding so I don't know really how to do it or if this works with databinding.
Thanks for your help :)
One way you can do that is setting the Tag property of your label:
l.Tag = liste[i];
Then, you can get your user back in the subscribed method:
var myUser = (User)((Label)sender).Tag;
But your friend is right: Data binding is a much better way. In fact, in most cases, you shouldn't have any code in the code behind file (other than the automatically generated code). Try looking for MVVM on your favorite search engine.
I need some help i need to color the text in rich text-box based on font type like if a string has "Times new roman" while other has "comics font " than both need to be color differently.Can any one help me out,I try to find some solution but most of them related to the coloring text "NOT"based on font.
Your question is a little vague, since you don't mention where you want to test. You could follow this link obtaining font that shows how to get the font in JQuery and then you can just decorate the css with your desired colour.
Now after understanding your question correctly, here is the solution:
Created RichTextBox control on the form:
rtb1
Following code should serve the purpose:
// Coloring on the basis of font
int boxLength = rtb1.TextLength;
int i = 0;
while (i < boxLength)
{
rtb1.Select(i, 1);
switch (rtb1.SelectionFont.Name)
{
case "Courier New": rtb1.SelectionColor = Color.Red;
break;
case "Times New Roman": rtb1.SelectionColor = Color.Green;
break;
default: rtb1.SelectionColor = Color.Black;
break;
}
i++;
}
To Test:
Paste random font from MS Word as follows
Before execution of code
After execution of code
Is this what is required?
I'm trying to create dynamically text box in WPF. It is very essential that I will have the flexibility to determine where the text box will be - in pixel level.
I have found many answers which use stackpanel to create "run-time" text box - but couldn't find how to construct it according to specified location.
the textbox has to be "word wrap" and I'm using a button click event to create the text box
this is the code for now, I really don't know which methods or properties will be helpful.
thanks :)
private void button1_Click(object sender, RoutedEventArgs e)
{
TextBox x = new TextBox();
x.Name = "new_textbox";
x.TextWrapping= TextWrapping.Wrap;
x.VerticalScrollBarVisibility=ScrollBarVisibility.Visible;
x.AcceptsReturn = true;
x.Margin = new Thickness(5, 10, 0, 0);
}
TextBox x = new TextBox();
x.Name = "new_textbox";
x.TextWrapping= TextWrapping.Wrap;
x.VerticalScrollBarVisibility=ScrollBarVisibility.Visible;
x.AcceptsReturn = true;
x.Margin = new Thickness(5, 10, 0, 0);
HouseCanvas.Children.Add(x);
Canvas.SetLeft(x, 20);
Canvas.SetTop(x, 20);
You probably want to place it in a Canvas, if you care about pixel placement of the textbox itself. You'll need to use x.SetValue(Canvas.LeftProperty, pixelX) [and .RightProperty, etc...] to get the position exactly right. Having not done this myself, I'd guess that you need to put the canvas in the right Z-order (on top), and make it transparent. There may also be issues with events, depending on the z-order. Good luck!
-Kev