|
Thanks a lot,but i was not looking for this answer !!
|
|
|
|
|
I need to set a printer to the default system printer from within my application developed using C#, any ideas?
teeka
|
|
|
|
|
You need to get the default printer and set it to PrinterSetting.PrinterName i dont know managed way to get the default printer name but you can use unmaaged Windows API function like GetDefaultPrinter some thing like
[DllImport("winspool.drv", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool GetDefaultPrinter(StringBuilder pszBuffer, ref int size);
in some where in your code write
StringBuilder defaultPrinter = new StringBuilder(256);
int size = dp.Capacity;
if (GetDefaultPrinter(defaultPrinter, ref size))
{
printDocument.PrinterSettings.PrinterName=defaultPrinter;
}
For More info look at
GetDefaultPrinter^]
GetDefaultPrinter at MSDN[^]
I hope this help
MCAD
-- modified at 14:38 Sunday 11th September, 2005
|
|
|
|
|
Hi All,
I want to make interface like the one made in Visual Studio .NET 2005 "like its window : " which contain dockable forms and tabs.
I want an article illustrate this subject or example
Thanks
|
|
|
|
|
This[^] is a very good control that provides docking and collapsing, just like VS .NET.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hello
I am creating some relationships in code. I have 3 tables Position, Department, and Employee. The relationship is a one to many for these tables. See the details below.
PositionNames are manager, secretary etc
Position - PositionID (PK), PositionName
Department - DepartmentCode (PK), NameOfDepartment
Employee - EmployeeNo (PK), Name, Address, PositionID(FK), DepartmentCode(FK)
I have created a relation with the department and employee as follows:
<br />
DataColumn parentColumn = ds.Tables["Department"].Columns["DepartmentCode"]; <br />
DataColumn childColumn = ds.Tables["Employee"].Columns["DepartmentCode"]; <br />
<br />
ds.Relations.Clear(); <br />
dRelEmployees = new DataRelation("EmployeeDetails",parentColumn,childColumn); <br />
ds.Relations.Add(dRelEmployees); <br />
My problem is l want to add another parent column for the position, do l need to repeat all this code just for the position table. Or can l add another parentColumn and add them all to the dRelEmployees DataSet.
Not sure how to do this.
Thanks in advance,
Steve
|
|
|
|
|
As the relations are two separate relations, you have to add two separate DataRelaction objects to the Relations collection.
To create the second DataRelation object, you need a reference to the partent column and child column.
So, yes, it's most of that code all over again.
---
b { font-weight: normal; }
|
|
|
|
|
Please tell me how to go about taking an existing, working C# application and web enable it.
Rather than produce Windows output as it now does, I need to get it to produce output that can be accessed from a web browser. The output is very simple and contains no clever bits just text and two buttons, one to Print and one for Done.
Regards,
Alf Stockton
-- modified at 2:07 Sunday 11th September, 2005
|
|
|
|
|
Please don't double post.
---
b { font-weight: normal; }
|
|
|
|
|
Is it possible to add a placeholder to a datatable?
If so, how?
Thanks.
|
|
|
|
|
Can you give an example of what you are trying to do?
|
|
|
|
|
I am trying to make a class library that contains some drawing routines for example:
public GraphicsPath DrawRoundRect( Pen p, float X, float Y, float width, float height, float radius)
{
GraphicsPath gp=new GraphicsPath();
gp.AddLine(X + radius, Y, X + width - (radius*2), Y);
gp.AddArc(X + width - (radius*2), Y, radius*2, radius*2, 270, 90);
gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius*2));
gp.AddArc(X + width - (radius*2), Y + height - (radius*2), radius*2, radius*2,0,90);
gp.AddLine(X + width - (radius*2), Y + height, X + radius, Y + height);
gp.AddArc(X, Y + height - (radius*2), radius*2, radius*2, 90, 90);
gp.AddLine(X, Y + height - (radius*2), X, Y + radius);
gp.AddArc(X, Y, radius*2, radius*2, 180, 90);
gp.CloseFigure();
return gp;
}
The compiler doesn's know what GraphicsPath is so you add
using System.Drawing.Drawing2D;
Then the compiler says can resolve symbol Drawing.
Of course all works fine if you are in the applications main form.
How do I get around this problem?
|
|
|
|
|
Hello
Check, that you have added System.Drawing to your project references. Right-click on References folder of your project and select "Add Reference".
With best regards,
Andrew
|
|
|
|
|
I had added System.Drawing but being new to C# I had not added a reference.
Thank you very much.
|
|
|
|
|
I have a WinForm that contains a RectF. I have methods to draw inside the RectF as in, DrawLine(...).
I also have a bool flag in a try/catch block that throws up a MessageBox if the line params (they come from TextBoxes linked to Button events) are false.
Now here's the problem....
When I click the "OK" or the "x" on the MessageBox, the line(s) gets erased partially, based on where the MessageBox overlapped the line.
The RectF, the graph axes and labels all remain. What's up w/ that??
thanks....
Here's some of the code.....
////////////////////////////////////////////////////////////////////////
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
DrawGraphRectF(e.Graphics);
DrawXYAxes(e.Graphics);
DrawGraphXandYTicks(e.Graphics);
}
//Background "reference" rectangle
void DrawGraphRectF(Graphics g)
{
Pen rectPen = new Pen(Color.BlueViolet);
g.DrawRectangle(rectPen, xIndent, yIndent, graphRect.Width, graphRect.Height);
g.FillRectangle(new SolidBrush(Color.Snow), xIndent + 1, yIndent + 1, graphRect.Width - 1, graphRect.Height - 1);
rectPen.Dispose();
}
//Draw x and y axes.
void DrawXYAxes(Graphics g)
{
Pen axisPen = new Pen(new SolidBrush(Color.BlueViolet), 1);
g.DrawLine(axisPen, xIndent, yIndent + graphRect.Height/2, xIndent + graphRect.Width, yIndent + graphRect.Height/2);
g.DrawLine(axisPen, xIndent + graphRect.Width/2, yIndent, xIndent + graphRect.Width/2, yIndent + graphRect.Height);
axisPen.Dispose();
}
//Draw tick marks on the axes.
void DrawGraphXandYTicks(Graphics g)
{
Pen tickPen = new Pen(new SolidBrush(Color.Black), 1);
//Draw x-axis ticks and label graph.
float fxAxis = -8.0f;
float fyAxis = 8.0f;
PointF xtickPoint = new PointF(xIndent, yIndent + graphRect.Height/2);
PointF ytickPoint = new PointF(xIndent + graphRect.Width/2, yIndent);
Font labelFont = new Font("Courier",6);
SolidBrush labelBrush = new SolidBrush(Color.Black);
StringFormat strFmt = new StringFormat();
//Draw x axis ticks and float labels.
for(float fx = 2 * xtickPoint.X; fx <= graphRect.Width; fx += xtickPoint.X)
{
//string measureString = f.ToString("f1");
//float measureLength = measureString.Length;
if(fxAxis == 0.0f)
{
fxAxis += 1.0f;
fx += xtickPoint.X;
}
g.DrawLine(tickPen, fx, xtickPoint.Y - 2, fx, xtickPoint.Y + 2);
g.DrawString((fxAxis > 0? "+" : "" ) + fxAxis.ToString("f1"), labelFont, labelBrush, fx - 7, xtickPoint.Y + 7);
fxAxis++;
}
//Draw y-axis ticks and float labels.
for(float fy = 2 * ytickPoint.Y; fy <= graphRect.Height; fy += ytickPoint.Y)
{
if(fyAxis == 0.0f)
{
fyAxis -= 1.0f;
fy += ytickPoint.Y;
}
g.DrawLine(tickPen, ytickPoint.X - 2, fy, xtickPoint.Y + 2, fy);
g.DrawString((fyAxis > 0? "+" : "") + fyAxis.ToString("f1"), labelFont, labelBrush, ytickPoint.X + 5, fy - 3);
fyAxis--;
}
tickPen.Dispose();
}
private void complexA_OK_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen cmplxPen = new Pen(Color.Coral, 4);
//
try
{
bShowValue = true;
mValReal = Convert.ToDouble(this.textComplexAReal.Text);
mValComplex = Convert.ToDouble(this.textComplexAComplex.Text);
DrawComplexNumber(g,cmplxPen, mValReal, mValComplex);
bShowValue = false;
}
catch
{
MessageBox.Show("Invalid Complex A Number", "Error!");
}
}
private void complexB_OK_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen cmplxPen = new Pen(Color.Green, 4);
//
try
{
mValReal = Convert.ToDouble(this.textComplexBReal.Text);
mValComplex = Convert.ToDouble(this.textComplexBComplex.Text);
DrawComplexNumber(g, cmplxPen, mValReal, mValComplex);
}
catch
{
MessageBox.Show("Invalid Complex B Number", "Error!");
}
}
void DrawComplexNumber(Graphics g, Pen cmplxPen, double re_, double im_)
{
g.DrawLine(cmplxPen, (xIndent + graphRect.Width/2), (yIndent + graphRect.Height/2), (xIndent + graphRect.Width/2) + (float)(re_ * xIndent), (yIndent + graphRect.Height/2) - (float)(im_ * yIndent));
}
private void button1_Click(object sender, System.EventArgs e)
{
Invalidate();
}
}
}
|
|
|
|
|
This is happening because you're doing some drawing from a button click event. Thereis no code in your Paint event to redraw these objects when the form is told to repaint itself.
Your app must keep a "state" that contains everything the Paint event needs to know to redraw everything at any time, not just wehen you click a button on your form.
Think about this. You have a button on your form that when you click, you add a random line to the form. Now, if you drew the line from inside the Click event of the button, the line will only be drawn once, ever! If the form is overlayed by another app or form and then moved out of the way, the Paint event doesn't know anything about the line that was drawn, so it can't be redrawn when the form is repainted.
But, if you add the endpoints of the line to an array and your Paint event is coding to redraw the lines using the data in the array, there's no problem. If the lines get overlapped by another app or form, then the app or form is moved out of the way, the Paint event now knows how to redraw the lines.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I've asked this question a couple of time, but never seem to get any replies. I'm not sure if it's just because it's impossible to do or what, but I'm going to give it one more try.
Is there anyway in C# to be notified of changes in the time (i.e. the clock in the system tray). For example if I want to know when the time changes from 4:00 to 5:00 or when the minute changes. Is this possible at all?
Any bit of help will be very appreciated.
Thanks.
- Aaron
|
|
|
|
|
To be notified when time changed
add using Microsoft.Win32; use SystemEvents to subscribe to TimeChanged event some thing like
SystemEvents.TimeChanged +=new EventHandler(SystemEvents_TimeChanged);
and in your event handler
private void SystemEvents_TimeChanged(object sender, EventArgs e)
{
MessageBox.Show("Time Changed");
}
Know run your program and change your time message box Will be displayed
MCAD
|
|
|
|
|
This event fires when the user changes the system time, not when the hour changes or the minutes changes.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Yes I Know that he said
Is there anyway in C# to be notified of changes in the time (i.e. the clock in the system tray
So i gave him this answer
MCAD
-- modified at 13:30 Sunday 11th September, 2005
|
|
|
|
|
He posted the question a couple times before, but just worded it a bit differently. I didn't mean to smack you for the wrong answer. Sorry...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
There is no event like this.
You'll have to create your own component to minitor the current time and fire events of your own when the hour and/or minute changes.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
If you mean when the user changes the time then Mohamad gave you the correct answer.
If you want a timer, then you might be interested in this: http://www.codeproject.com/dotnet/ABTransClockArticle.asp[^]
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
The article seems to be what I'm looking for.
Thanks for the help.
- Aaron
|
|
|
|
|
Um... This may come as a shock to you, but the time is changing constantly. It never stops changing. Even when you turn off the computer.
However, if you want notifications of minute and hour changes, it would be quite simple to use a timer that in turn keeps track of those transitions and calls OnMinute and OnHour events.
Matt Gerrans
|
|
|
|
|