|
Hi all,
i draw a string diagonal on my Panel,
and draw this text with opacity option
get color for text like below:
PrintPageEventArgs pe;
int X = 0;
int Y = 0;
RectangleF rect2 = panel2.ClientRectangle;
float image_draw_wd = panel2.Width;
float image_draw_ht = panel2.Height;
Brush myBrush = new SolidBrush(Color.FromArgb(128, Color.Blue));
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.FormatFlags = StringFormatFlags.LineLimit;
stringFormat.Trimming = StringTrimming.Word;
SizeF sz = pe.MeasureString(panel2.watermarkText, panel2.watermarkFont, (int)image_draw_wd, stringFormat);
double angle = 0;
double angleRadians = Math.Atan2(image_draw_ht, image_draw_wd);
angle = angleRadians * 180.0 / Math.PI;
pe.TranslateTransform((rect2.Location.X + rect2.Width / 2), (rect2.Location.Y + rect2.Height / 2));
pe.RotateTransform((float)angle + flip180Image);
pe.TranslateTransform(-(rect2.Location.X + rect2.Width / 2), -(rect2.Location.Y + rect2.Height / 2));
X = (int)(panel2.Width - sz.Width) / 2;
Y = (int)(panel2.Height - sz.Height) / 2;
RectangleF dr_rect = new RectangleF(new Point(X, Y, new Size(image_draw_wd , ((int)sz.Height) + extra_margin));
pe.DrawString(panel2.watermarkText, panel2.watermarkFont, myBrush, dr_rect, stringFormat);
but when i print it, the text not fully visible
if i draw it horizontally its working fine.
i cant understand where is the problem
please help me for this.
thanks alot
modified 30-Nov-19 2:28am.
|
|
|
|
|
Quote: when i print it, the text not fully visible
if i draw it horizontally its working fine.
This doesn't make any sense to us without the code you used to cause the problem: try generating a tiny bit of code that shows it working and not working, and post that for us so we can see exactly what you are doing. It you can explain what you mean by "not fully visible" that would help as well - does the left side work, but not the right, or the top but not the bottom, or every second character is gone, or what? We don't know, and it's probably relevant.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Please check i update my question,
and please help now
|
|
|
|
|
That should crash: pe is null
PrintPageEventArgs pe;
...
SizeF sz = pe.MeasureString(panel2.watermarkText, panel2.watermarkFont, (int)image_draw_wd, stringFormat); You need to use the PrintPageEventArgs that is passed in as part of the PrintPage event or the metrics you use for MeasureString won't work anyway as they aren't relevant to the device context you are drawing on - even if you construct one somewhere and don't show it here.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
its not null its come from here
private void PrintDocument1_PrintPage(object sender, PrintPageEventArgs pe)
|
|
|
|
|
Thanks - I assumed it would, but when it's explicitly shown as a new declaration it needs to be confirmed.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
sorry to poor presentation
but please understand and help me
|
|
|
|
|
When you say "the text not fully visible" what exactly do you mean?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
is there any option to show the image how can i upload my drawing image to describe u better
|
|
|
|
|
No, because we get some idiots here who would post ... ummm ... objectional material
You wouldn't believe what tries to get through moderation ATM, and we can't moderate every post, there aren't enough of us volunteers to do that. And you don't have sufficient rep yet to store images here.
You could put it up on Dropbox / Google and provide a link?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
actual design like this
Actual_Label.png - Google Drive[^]
and printed like this
Label_print.png - Google Drive[^]
but when i draw string horizontally its print like original
one more thing when i check its print preview its looks perfect,so why its not print ok
thats why i cant understand where is the problem
modified 30-Nov-19 4:20am.
|
|
|
|
|
OK - I'm trying to duplicate exactly what you have, but ... your code won't compile without errors and I don't want to fix them in case I "fix them wrong".
For example:
RectangleF dr_rect = new RectangleF(new Point(X, Y, new Size(image_draw_wd, ((int)sz.Height) + extra_margin));
Missing a close bracket (at a guess, after the "Point(X, Y" is where it goes).
PrintPageEventArgs doesn't contain methods MeasureString, TranslateTransform, and RotateTransform: PrintPageEventAgrs.Graphics does.
If that is copy'n'pasted from your app, then it's possible you are testing an older version of your source - in which case the display fault may no longer exist if you fix that code.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
If I bodge up your code (fix the errors, use substitutes for external bits I don't have) it works ok in preview for me:
private void FrmMain_Shown(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += Pd_PrintPage;
PrintPreviewDialog pdi = new PrintPreviewDialog { Document = pd };
pdi.ShowDialog();
}
private void Pd_PrintPage(object sender, PrintPageEventArgs pe)
{
int X = 0;
int Y = 0;
RectangleF rect2 = panel2.ClientRectangle;
float image_draw_wd = panel2.Width;
float image_draw_ht = panel2.Height;
Brush myBrush = new SolidBrush(Color.FromArgb(128, Color.Blue));
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.FormatFlags = StringFormatFlags.LineLimit;
stringFormat.Trimming = StringTrimming.Word;
SizeF sz = pe.Graphics.MeasureString("A line of text to display", Font, (int)image_draw_wd, stringFormat);
double angle = 0;
double angleRadians = Math.Atan2(image_draw_ht, image_draw_wd);
angle = angleRadians * 180.0 / Math.PI;
pe.Graphics.TranslateTransform((rect2.Location.X + rect2.Width / 2), (rect2.Location.Y + rect2.Height / 2));
pe.Graphics.RotateTransform((float)angle);
pe.Graphics.TranslateTransform(-(rect2.Location.X + rect2.Width / 2), -(rect2.Location.Y + rect2.Height / 2));
X = 10;
Y = 10;
RectangleF dr_rect = new RectangleF(new Point(X, Y), new Size((int) image_draw_wd, ((int)sz.Height) + 10));
pe.Graphics.DrawString("A line of text to display", Font, myBrush, dr_rect, stringFormat);
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
i already mention in preview its ok
|
|
|
|
|
Yes, but your code doesn't compile, so that has to be taken with a pinch of salt!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
And if I change my code:
private void FrmMain_Shown(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += Pd_PrintPage;
PrintDialog pdi = new PrintDialog { Document = pd };
pdi.ShowDialog();
pd.Print();
It prints fine to PDF, XPS, OneNote, ...
So the code seems OK as far as I can see.
So ... what happens if you fix the compiler errors, and print to - say - OneNote?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
private void Pd_PrintPage(object sender, PrintPageEventArgs pe)
{
string watermarkText = "Your Name © 2015, All Rights Reserved";
Font watermarkFont = new Font("Microsoft Sans Serif", 18, FontStyle.Bold);
int X = 0;
int Y = 0;
RectangleF rect2 = panel2.ClientRectangle;
float image_draw_wd = panel2.Width;
float image_draw_ht = panel2.Height;
Brush myBrush = new SolidBrush(Color.FromArgb(128, Color.Blue));
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.FormatFlags = StringFormatFlags.LineLimit;
stringFormat.Trimming = StringTrimming.Word;
SizeF sz = pe.Graphics.MeasureString(watermarkText, watermarkFont, (int)image_draw_wd, stringFormat);
double angle = 0;
double angleRadians = Math.Atan2(image_draw_ht, image_draw_wd);
angle = angleRadians * 180.0 / Math.PI;
pe.Graphics.TranslateTransform((rect2.Location.X + rect2.Width / 2), (rect2.Location.Y + rect2.Height / 2));
pe.Graphics.RotateTransform((float)angle);
pe.Graphics.TranslateTransform(-(rect2.Location.X + rect2.Width / 2), -(rect2.Location.Y + rect2.Height / 2));
X = 10;
X = (int)(panel2.Width - sz.Width) / 2;
Y = 10;
Y = (int)(panel2.Height - sz.Height) / 2;
RectangleF dr_rect = new RectangleF(new Point(X, Y), new Size((int)image_draw_wd, ((int)sz.Height) + 10));
pe.Graphics.DrawString(watermarkText, watermarkFont, myBrush, dr_rect, stringFormat);
}
preview , pdf n all looks same n fine why its not print on actual printer
my model is
HP deskjet gt 5811
|
|
|
|
|
At a guess, driver problems.
I can't test that - I have a Samsung colour laser as I got fed up with inkjets never working when I needed them ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
ok thank u so much for your support
|
|
|
|
|
No problem - sorry I can't do more!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi,
I have a dialogue window. In that I have a label called "Filter By". Its of Combo box style.
I am trying to type a letter “e”. It should bring up the next item in the drop down that begins with “E” but instead closes the window.
Any suggestions on how to rectify this?
|
|
|
|
|
What kind of app? Windows Forms, WPF, ASP.NET ... ?
Also, without seeing any code behind the window, it's going to be quite difficult to tell you what's going on. Just dropping a ComboBox on a form and running it isn't going to do what you described at all, so there's got to be some code on the form that's not behaving like you expect.
|
|
|
|
|
|
As you haven't provided any real detail, the most detailed answer I can give is that you'll need to do a SELECT using your value.
|
|
|
|
|
"SELECT"? He didn't say it was a SQL based database. You're making a lot of assumptions here
|
|
|
|
|