|
Thanks, you had a great demonstration there. I have never thought of the redrawing when setting a property that causes invalidation before.
Thank you again, that answered my question perfectly.
Best regards,
Anıl Yıldız.
|
|
|
|
|
Why would you invalidate the control?
|
|
|
|
|
guys,
this is an example of a owner drawn control.. you dont have to invalidate the control if you just use the Windows.Forms.Button.. but if you write your own control this would be a solution for creating a properties that shall react by setting a new value..
he described the control as blablubb control this could be a button or anything else like a self written control
|
|
|
|
|
rootjumper wrote: this is an example of a owner drawn control
Then, yes, check inside the Control. But he was asking about setting Enabled from outside the Control.
|
|
|
|
|
Probably the first. Try it.
P.S. Look up "premature optimization".
|
|
|
|
|
I just experimented with the DataGridView I'm playing with. When Enabled is set to true when it is already true, a DataGridView does not redraw itself. It must therefore already perform the check you're considering adding. I would assume that that is true of all controls, but you should experiment with the particular control you're using.
Bottom line: adding the check is needless and wasteful.
|
|
|
|
|
Thanks for all the answers and sorry for the delayed reply. I'm not doing anything specific right now. The question has been in my mind for a while and I wanted to see if there were any people around who knows the answer. I was going to check that out for myself but you apparantly did it.
About validating, just like you got, it was just an idea if maybe the control validates itself when the Enabled property is set to anything no matter the value it had previously. That was a great direction for me which I've never thought about before.
Now that you are saying setting the Enabled property is not validating if it is just the same value as before. But it should be doing something right? Maybe checks it before and decides not to set it since it is just the same. Pretty much what the first answer said. Considering this is the case, I assume there is an IF statement to check the value already so it is a waste of cycles to check it beforewards.
It is not a very big deal but well, I just wanted to know. Thanks to everyone who has taken the time reading and even answering. They are very valuable to me.
Best regards,
Anıl Yıldız.
|
|
|
|
|
definatly thanks man
|
|
|
|
|
no the check will be only performed if YOU code it (self written controls.. all others control i.e. from microsoft will perform the check i would suppose) ^^
try to write your own control which will be drawn white if property Active is true and black if is false by only changing the value without calling repaint methods on property change.. this is not wasteful! you need to look at the point of view
|
|
|
|
|
I've never needed to (yet), but I'm doing some drawing on this DataGridView after it draws itself.
I added a handler for the Paint event to accomplish that, and I confirmed that Paint does not get called when Enabled is unchanged.
The state is checked inside, so checking it from outside is wasteful.
Unless the Control was developed by someone who doesn't know to check it inside and just always redraws.
|
|
|
|
|
On an application that uses ID Automation logic building barcodes the same caracters passed on application are represented deifferent on another application, why could be that problem
regards!
Qendro
|
|
|
|
|
What kind of characters? How are they formatted/stored?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
the caracters are 1500011600190121KLM090034557908K0000000000000098 so these caracters are builded as barcode on different way in my application rather than on an application that I downloaded it as a demo that uses also IDAutomation(CODE 128).
Qendro
|
|
|
|
|
Hello all! It's now 8:10 am and I have been trying multiple solutions since 9:00 pm. I figured this would be a simple task and wow, have I been proven wrong.
First, I have been utilizing a print class (subclass) to handle my printing needs. I've been asked to have different font sizes utilized for the same page. Sounds simple...um, no. In VB6 I remember doing anything I wanted in printing! This is the only app I've had that required printing to a receipt printer or a laser printer.
I was sending multiple print calls to separate my font size parameters:
string text = "**ONLINE ORDER**\r\n\r\n" +
"Order Ready at:\r\n";
var printHead = new ReceiptPrint();
printHead.TextToPrint = text;
printHead.Print();
text = deliveryDate.ToShortDateString() + "\r\n" + deliveryTime.ToShortTimeString() + "\r\n";
var printDT = new ReceiptPrint();
printDT.PrinterFont = new Font("Arial", 20);
printDT.TextToPrint = text;
printDT.Print();
Unfortunately, this will print a separate page for each printer call. Is there anything I can research (specifically) to print text with varied font sizes on the same page? I know it has to be possible because apps print multiple font sizes, colors, etc. all the time. I do not want the print dialogue box to appear, this needs to print to direct to default printer.
Can anyone offer some insight or point me in the right direction, please?
James
|
|
|
|
|
What is RecieptPrint? I assume that is what you meant by sub-class?
I tend to use a class that inherits from PrintDocument, which overrides the OnPrintPage function. This function has an argument for PrintPageEventArgs which has a graphics class which you can draw on (basically the paper to be printed).
I can draw whatever I want on here, fonts in any size or colour etc, no problems.
I think your problem is your RecieptPrint class is too limited and needs expanding. How does it print the text?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Thank you for your quick reply.
ReceiptPrint is my subclass that inherits from PrintDocument.
I can draw whatever I want also, the problem is I need to utilize the class in a way that I can send multiple strings with various font sizes, then print all of them.
When I have attempted this, it only prints in one font size.
Here is the class for you to peek at:
class ReceiptPrint : PrintDocument
{
#region Property Variables
private Font _font;
private string _text;
#endregion
#region Class Properties
public string TextToPrint
{
get { return _text; }
set { _text = value; }
}
public Font PrinterFont
{
get { return _font; }
set { _font = value; }
}
#endregion
#region Static Local Variables
static int curChar;
#endregion
#region Class Constructors
public ReceiptPrint() : base()
{
_text = string.Empty;
}
public ReceiptPrint(string str) : base()
{
_text = str;
}
#endregion
#region OnBeginPrint
protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e)
{
base.OnBeginPrint(e);
if (_font == null)
{
_font = new Font("Arial", 10);
}
}
#endregion
#region OnPrintPage
protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
{
base.OnPrintPage(e);
int printHeight;
int printWidth;
int leftMargin;
int rightMargin;
Int32 lines;
Int32 chars;
{
printHeight = base.DefaultPageSettings.PaperSize.Height - base.DefaultPageSettings.Margins.Top - base.DefaultPageSettings.Margins.Bottom;
printWidth = base.DefaultPageSettings.PaperSize.Width - base.DefaultPageSettings.Margins.Left - 0;
leftMargin = base.DefaultPageSettings.Margins.Left = 0;
rightMargin = base.DefaultPageSettings.Margins.Top = 0;
}
if (base.DefaultPageSettings.Landscape)
{
int tmp;
tmp = printHeight;
printHeight = printWidth;
printWidth = tmp;
}
Int32 numLines = (int)printHeight / PrinterFont.Height;
RectangleF printArea = new RectangleF(leftMargin, rightMargin, printWidth, printHeight);
StringFormat format = new StringFormat(StringFormatFlags.LineLimit);
e.Graphics.MeasureString(_text, PrinterFont, new SizeF(printWidth, printHeight), format, out chars, out lines);
e.Graphics.DrawString(_text, PrinterFont, Brushes.Black, printArea, format);
curChar += chars;
e.HasMorePages = false;
}
#endregion
#region RemoveZeros
public int RemoveZeros(int value)
{
switch (value)
{
case 0:
return 1;
default:
return value;
}
}
#endregion
}
|
|
|
|
|
jameschristianii wrote: //Fit as many characters as we can into the print area
e.Graphics.MeasureString(_text, PrinterFont, new SizeF(printWidth, printHeight), format, out chars, out lines);
//Print the page
e.Graphics.DrawString(_text, PrinterFont, Brushes.Black, printArea, format);
This is where your restriction is. You need to change the printer font here depending on what you want to print. Your problem is you are only using one string of text, if you want different parts to be different font you need to break it up. Try having a collection property with a list of structs containing text and fonts, and print each as if it was a new line.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
You're design is completely hosed up. You're printing a new page for every line of test your outputting. You can only call the Print method once per page, so you have to do all of your drawing before you call Print. So, you're PrintDocument class is going to need to know what the page looks like, every line, every image, so when Print is called, it can draw all of this stuff on the Graphics object that you get in the OnPrintPage event.
You basically need to implement some method of passing font, string, and drawing commands to your PrintDocument class. That class has to maintain a database of all of these commands. When the OnPrintPage event fires, your code has to go through all of these commands and execute them, one at a time, drawing each element of the page.
|
|
|
|
|
I was attempting to implement something to what you are saying. I didn't know the exact approach at doing that. I was trying to use a stringbuilder but my results were ineffective. I'm assuming I needs a means of implementing a flag for each string of text, correct?
Thank you.
|
|
|
|
|
Think of each string of text as an object that needs to be drawn on the page. Each object needs to supply certain things to your drawing engine. The first, obvisouly, is the text that needs to be drawn. You also need to know where on the page the text needs to be drawn and in what font, style, and size. In your OnPrintPage event handler, the code needs to enumerate the collection of these objects and draw each string at the position where it needs to be and with the correct font.
To use something like this, you'd probably do something like:
ReceiptPrint receipt = new ReceiptPrint();
receipt.AddDrawCommand(new TextDrawCommand("Some Store Header Text", "Arial", 16, FontStyle.Bold));
receipt.AddDrawCommand(new TextDrawCommand("Some Address Text", "Courier New", 10, FontStyle.Normal));
receipt.AddDrawCommand(new TextDrawCommand("------------------------", "Courier New", 10, FontStyle.Normal));
foreach(...)
receipt.AddDrawCommand(new TextDrawCommand(ItemText, "Arial", 10, FontStyle.Normal));
receipt.Print();
|
|
|
|
|
Ok, I understand what you are saying (It is similar to what I was trying to do earlier this morning), but I am unsure as to how I would go about the method you're suggesting. It was inside my class that I couldn't quite get the collection correct. I wasn't sure as to how I would set the object (string, font) and pass the object to the DrawString by looping through the collection.
|
|
|
|
|
Any one have a suggestion / idea / recommendation as to how (Or where I can research) a solution?
|
|
|
|
|
Can someone point me in a direction as to how to resolve this? I have been scouring the internet for hours trying too many things that aren't working completely.
Thank you,
James
|
|
|
|
|
I've Created one Desktop Application which has server client access... Every user will has different login. Now the problem is, when one user is login, the same user cannot be login from other pc... The msg should come as the 'user is already Login'. In ASP.Net, it can be achieved through session.. But, how can I do this in Desktop Application. There is one solution.. We can maintain one log table for the logined users. But, that too will face deadlock situation.... Is any other solution for the single user login??
|
|
|
|
|
Shalini_U wrote: I've Created one Desktop Application which has server client access
When you say server/client access, do you mean you have both a server app and a client app? if so, then the server app will easily be able to keep a list of logged in users and validate the login.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|