|
But I still wonder... why did he ask?
a simple google result for three terms - 'c# date add' gave me enough resources to read...
Are there really people who still don't depend on GOOGLE? I am Impressed.
|
|
|
|
|
asking here is a ticket for a break; you "have" to wait for a descent reply.
Google's main disadvantage is it leads to results much too quickly...
There is an opportunity for a slow search engine, something that replies with a splash screen, saying:
I'm working for you; accumulating possible answers to your query; please wait; ETA 7 minutes and counting.
If CP were to offer such a gateway to Google, it would not have server overloads ever again...
|
|
|
|
|
Luc... u amaze me with your answers...
I have been missing this insight for so long...
Now, I am sure that Google cannot tell me this side of the story!!!
|
|
|
|
|
What's a Google?
Edit: I seem to recall a product from the '70s called "Coogle" -- I think was peanut butter and jelly in one jar, but I could be wrong.
|
|
|
|
|
|
PIEBALDconsult wrote: What's a Google?
it's a dull binge.
PIEBALDconsult wrote: "Coogle"
Pretty klose[^].
|
|
|
|
|
|
You're welcome.
Another question solved by a minor Google action.
|
|
|
|
|
Bing would have found it if I'd spelled it correctly...
|
|
|
|
|
Google gave plenty when asked for Coogle peanut butter and jelly , the first hit was a CodeProject message (and that happens a lot)!
|
|
|
|
|
Luc Pattyn wrote: that happens a lot
You don't say.
|
|
|
|
|
Hi, is there some UML(rational rose)(class diagram) tool where I can draw my database design and generate SQL scripts for creating my database?
modified on Wednesday, March 31, 2010 11:43 AM
|
|
|
|
|
Not sure which forum this should be in, but C# isn't it.
also
Rational Rose != UML
Class Diagram != Table Diagram.
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
Hi,
I've got a form with a gradient background. On that form I places a tabcontrol. But when I a hover a tab of the tabcontrol, the tab starts flickering a lot. Is there any way to stop this flicker?
I have already found some solutions. One of them is to create a custom control which inherits from System.Windows.Forms.Tabcontrol.
I dit this and the flicker is gone, but when I use the following code, the font on my tabs isn't the default font like the rest of my form.
public class DoubleBufferedTabControl : TabControl
{
private System.Drawing.Bitmap buffer;
public DoubleBufferedTabControl()
{
this.SetStyle(ControlStyles.UserPaint | ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
}
protected override void OnPaint(PaintEventArgs e)
{
this.SetStyle(ControlStyles.UserPaint, false);
base.OnPaint(e);
System.Drawing.Rectangle o = e.ClipRectangle;
System.Drawing.Graphics.FromImage(buffer).Clear(System.Drawing.SystemColors.Control);
if (o.Width > 0 && o.Height > 0)
DrawToBitmap(buffer, new System.Drawing.Rectangle(0, 0, Width, o.Height));
e.Graphics.DrawImageUnscaled(buffer, 0, 0);
this.SetStyle(ControlStyles.UserPaint, true);
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
buffer = new System.Drawing.Bitmap(Width, Height);
}
}
So if there is no easy way to stop this flicker, how can i get the font on my tabs just like the font of the rest of my form?
|
|
|
|
|
Hi,
1.
The tab labels of TabPages are drawn by the TabControl, using the font in its Font property.
2.
The code you have shown looks horrible:
- I've never seen anything change the ControlStyles inside a Paint handler;
- I doubt your bitmap coordinates are correct; what if the ClipRectangle is not located at (0,0)?
- you create a Graphics (that is expensive and slow) without disposing of it;
- as far as I know DrawToBitmap fails to paint some Controls, I hope you don't have listing controls (ListBox, TreeView, WebBrowser...) on your TabPages.
- does this work at all when printing?
You also forgot to dispose of the bitmap inside OnResize.
3.
I would have tried solving the flickering with a Panel; so rather than putting the TabControl on the Form with background image, put it on a Panel of its own size, then put the Panel on the Form. Not sure it would work but if it does, it would be a lot simpler and faster.
|
|
|
|
|
thanks for the help,
luckily the presented code wasn't mine I've found the code somewhere and I thought it may could be a lead.
I don't want the tabcontrol to be placed on a panel because of the gray bound that would be visible next to the tabs. I could create a transparent panel, but that would probably cause as much flicker as now.
so that leads me back to my first question: is there a way to reduce this flicker?
|
|
|
|
|
There always will be some flickering, it inherently is present due to the fact that parts of a Control needs to be erased and redrawn when something changes. So the trick is to keep the time between start of erasure and end of repaint as short as possible. That means:
- keep Form complexity low (avoid large number of controls, avoid background images, avoid transparency);
- keep computations low (get your data ready before you start repainting; only invalidate what really changes);
- keep memory burden low (avoid creating expensive objects such as Graphics; avoid garbage collection while repainting; make sure to dispose correctly);
- and finally: avoid erasure by using double-buffering (which erases and paints in memory, then copies as fast as it can to the screen).
That's all!
|
|
|
|
|
I am not sure if this is gonna work... But worth a try.
Have you set your form'd doublebuffered property to true? Since you are custom painting the background, it makes sense to use double buffer.
Then try using usual TabControl.
|
|
|
|
|
Yes,
the double buffering of the form is on. But that doesn't help.
the problem is that a classic tabcontrol doesn't have a property doublebuffered. That is why i created a custom control which inherits from TabControl. In that custom control, i set the doublebuffered property to true.
grtz
|
|
|
|
|
I have the following code which prints three RichTextBox controls to a page. The format is Avery 5388 which is the perforated index card stock paper (8.5x11). The print preview shows the text in each box but the lines don't wrap.
Any way to fix the wrapping problem?
private void fcPrintDocument_PrintPage( object sender, PrintPageEventArgs e )
{
cardDataTabPage.Focus();
DrawPage( e.Graphics );
}
private void DrawPage( Graphics graphics )
{
Graphics g = graphics;
Pen boxPen = new Pen( Brushes.Black );
int pageWidth = fcPrintDocument.DefaultPageSettings.PaperSize.Width;
int pageHeight = fcPrintDocument.DefaultPageSettings.PaperSize.Height;
RectangleF srcRect = cardDataTabPage.ClientRectangle;
RectangleF destRect = new Rectangle( 0, 0, pageWidth, pageHeight );
float scaleX = destRect.Width / 850;
float scaleY = destRect.Height / 1100;
for ( int i = 0; i < cardDataTabPage.Controls.Count; i++ )
{
if ( cardDataTabPage.Controls[i].GetType() == richTextBox1.GetType() )
{
RichTextBox rich = (RichTextBox)cardDataTabPage.Controls[i];
g.DrawRectangle( boxPen, rich.Bounds );
g.DrawString( rich.Text, rich.Font, Brushes.Black,
rich.Bounds.Left * scaleX, rich.Bounds.Top * scaleY, new StringFormat() );
}
}
}
Thanks.
|
|
|
|
|
Hi,
you're not printing a RichTextBox at all, you are simply painting its textual content, in a single font, style, and color, at a specific point without taking care of width and height. There are DrawString overloads that take a Rectangle and perform a word wrap for you, keeping everything in the allotted width.
If you really want to print an RTB, you need to call some Win32 functions, using P/Invoke.
|
|
|
|
|
I figured it out after I found a reference that states: when passing a RectangleF as one of the parameters, DrawString automatically wraps the text inside the destination's bounding rectangle.
So I changed by method call to:
RectangleF cardBox = new RectangleF( rich.Bounds.X + 5, rich.Bounds.Y + 5, rich.Bounds.Width - 5, rich.Bounds.Height - 5 );
g.DrawString( rich.Text, rich.Font, Brushes.Black, cardBox, frmt );
The 'cardBox' rectangle is deflated by 5 pixels for padding. I also included a StringFormat to center the text on the card.
Mark
|
|
|
|
|
you want -10 to center, not -5, and even that is just an approximation as it will paint flush left.
to really center, you need to use Graphics.MeasureString to find actual width, then adjust Left (and maybe Top) while keeping the original Width and Height.
|
|
|
|
|
Hi,
Just a quick question for people. How do I pass TextWriter through a function?
My main opens a TextWriter called LogWritter.
I want to create a function which has this log file passed to it so I can write to it from within this seperate function. I want my program to look like this:
Main()
{
TextWriter LogWriter = new StreamWriter(LogLocation);
for (i=0... etc loop
{
MyFunction(LogWriter)
}
}
</per>
<pre>
MyFunction(TextWriter LogWriter)
{
LogWriter.WriteLine("Hello World")
}
I would expect Hello World to be written as many times as looped in LogLocation. How come this does not appear to work? When I run this the file in LogLocation remains blank.
Many Thanks
Steve
|
|
|
|
|
You don't flush the text writer or close it. If you check the file before the writer is garbage collected, you can't be certain what will be in the file.
This should fix your problem:
Main()
{
using (TextWriter LogWriter = new StreamWriter(LogLocation))
{
for (i=0... etc loop
{
MyFunction(LogWriter)
}
}
}
MyFunction(TextWriter LogWriter)
{
LogWriter.WriteLine("Hello World")
LogWriter.Flush()
}
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|