|
A better question would be: how many bugs or weaknesses are there in the method
MyFunction() ? I found 4 so far.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
|
How does that fit with "More functions should disregard input values and just return 12. It would make life easier." as quoted by Malcolm Smart ??
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
seemamltn wrote: Re: What is output
According to Wikipedia, "output" is "any data exiting a computer system. This could be in the form of printed paper, audio, video. In the medical industry this might include CT scans or x-rays. Typically in computing, data is entered through various forms (input) into a computer, the data is often manipulated, and then information is presented to a human (output)."
Hope this answers your question.
/ravi
|
|
|
|
|
I use following code in C# to print pdf files, it works ok, I want to use printer's IP address instead of printer's name, any help?
private static void doPrint(string executable, string fileFullPath, string printerName)
{
// Print PDF file using Acrobat Reader.
// "/h" - hidden mode
// "/t" - print command following by the file name and printer name
System.Diagnostics.ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.Arguments = "/h /t \"" + fileFullPath + "\" \"" + printerName + "\"";
startInfo.FileName = executable;
startInfo.UseShellExecute = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
System.Diagnostics .Process process = new Process() ;
try {
process = Process.Start(startInfo);
}
catch (Exception ex)
{
DBMaint.updateLogFile (ex.Message.ToString ());
}
finally
{
process.WaitForExit(20000);
if (process.HasExited == false)
{
process.Kill();
}
}
}
|
|
|
|
|
Each printer has a port for accessing that if you put the port name instead the printer name it would work.
ports for network printers define like this \\Hostname\portName [somewhat like printerName but not exactly] and you can put IP of the host instead of the name.
so you should do 2 things first find the printer port and second find the IP of the host
the first one need some works to do, one of the ways is to use WMI through System.Managment namespace in .NET
and here is the script you need for retrieving printers information
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
arrComputers = Array("TITAN")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PrinterShare", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo "Antecedent: " & objItem.Antecedent
WScript.Echo "Dependent: " & objItem.Dependent
WScript.Echo
Next
Next
just use the query part to create and use it
Here is the code for showing the Printer ports
ManagementObjectSearcher search = new ManagementObjectSearcher(new SelectQuery("Win32_Printer"));
ManagementObjectCollection moc = search.Get();
foreach (ManagementObject mo in moc)
MessageBox.Show(mo.Properties["Name"].Value.ToString()+" Port: "+mo.Properties["PortName"].Value.ToString());
and the second part is fairly easy just use the Dns.GetHostEntry method to get the IP
and at last I test your code with this method and it works
hope the post would be useful
|
|
|
|
|
Thanks for the very usful information, it works for my project.
But I had little problem also, when I run it from my computer, it's ok, when I deployeed to another computer and scheduled in windows task, I got error,debug window pop up, in windows task log file, it exited with code C000005.
I couldn't figure out what cause the error.
Any help again??
Thanks a lot.
|
|
|
|
|
|
I am using GDI methods (ROP/XOR methods) to draw a reversible rectangle on FORM_A. When I display another form FORM_B (Dialog) on top of FORM_A and close it (FORM_B), part for of the reversible rectangle (where FORM_B was displayed) is erased. I tried calling FORM_Update and FORM_Paint events from FORM_Activated event. It worked in single form application but not in MDI application. Any suggestions are appreciated.
Cheers,
Prasad
|
|
|
|
|
Wow - you're still going with this ? You need to invalidate the form that is being obscured, if it's not working in an MDI app, then you're invalidating the wrong thing. Having said that, showing and hiding a form, should fire the paint event on it's own. You do NOT call the paint event, you call Invalidate() to force it to fire.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks for your answer. Still it is not working. If I use Invalidate() method it is completely erasing the rubberband rectangle.
I do not think that is the answer (may be I am wrong)
Regards,
Prasad
|
|
|
|
|
There are two rules to get it right:
- do all painting inside a Paint handler (and nowhere else);
- call Invalidate() if you have changed the parameters of the paintable objects.
If it does not behave, it's because you did not obey the above rules.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks for the reply. I cannot handle all the painting inside paint event handler, because reversible rectangles must be drawn inside mouse eventhandlers.
I am attaching all the code (although it is long), please let me know what modifications I have to make.
<br />
<br />
using System;<br />
using System.Windows.Forms;<br />
using System.Drawing;<br />
<br />
namespace RubberbandShape<br />
{<br />
class MainForm : System.Windows.Forms.Form<br />
{<br />
public MainForm()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
void InitializeComponent() {<br />
this.button1 = new System.Windows.Forms.Button();<br />
this.SuspendLayout();<br />
this.button1.Location = new System.Drawing.Point(323, 256);<br />
this.button1.Name = "button1";<br />
this.button1.Size = new System.Drawing.Size(75, 23);<br />
this.button1.TabIndex = 0;<br />
this.button1.Text = "button1";<br />
this.button1.UseVisualStyleBackColor = true;<br />
this.button1.Click += new System.EventHandler(this.button1_Click);<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.AutoValidate = System.Windows.Forms.AutoValidate.EnablePreventFocusChange;<br />
this.ClientSize = new System.Drawing.Size(401, 282);<br />
this.Controls.Add(this.button1);<br />
this.DoubleBuffered = true;<br />
this.Name = "MainForm";<br />
this.Text = "Rubber Band Shape Drawing";<br />
this.Paint += new System.Windows.Forms.PaintEventHandler(this.MainForm_Paint);<br />
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.MainForm_MouseUp);<br />
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MainForm_MouseMove);<br />
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MainForm_MouseDown);<br />
this.ResumeLayout(false);<br />
<br />
}<br />
<br />
[STAThread]<br />
public static void Main(string[] args)<br />
{<br />
Application.Run(new MainForm());<br />
}<br />
<br />
private bool mouseDown = false;<br />
private bool mouseMoving = false;<br />
private bool haveRect = false;<br />
private int XDown;<br />
private int YDown;<br />
private int oldX;<br />
private Button button1;<br />
private int oldY;<br />
<br />
void MainForm_MouseDown(object sender,<br />
System.Windows.Forms.MouseEventArgs e)<br />
{<br />
if( e.Button == MouseButtons.Left )<br />
{<br />
mouseDown = true;<br />
XDown = e.X;<br />
YDown = e.Y;<br />
mouseMoving = false;<br />
}<br />
else if( e.Button == MouseButtons.Right )<br />
{<br />
if( haveRect )<br />
{<br />
haveRect = false;
Invalidate();
}<br />
}<br />
}<br />
<br />
void MainForm_MouseMove(object sender,<br />
System.Windows.Forms.MouseEventArgs e)<br />
{ <br />
if( mouseDown )<br />
{<br />
using (Graphics g = Graphics.FromHwnd(this.Handle))<br />
{<br />
if (mouseMoving)<br />
RubberRectangle(g, XDown, YDown, oldX, oldY);<br />
RubberRectangle(g, XDown, YDown, e.X, e.Y);<br />
mouseMoving = true;<br />
oldX = e.X;<br />
oldY = e.Y;<br />
}<br />
}<br />
}<br />
<br />
void MainForm_MouseUp(object sender,<br />
System.Windows.Forms.MouseEventArgs e)<br />
{ <br />
mouseDown = false;<br />
mouseMoving = false;<br />
haveRect = true;<br />
}<br />
<br />
private void RubberRectangle(Graphics g, int X1, int Y1, int X2, int Y2 )<br />
{ <br />
RubberbandRectangle rect = new RubberbandRectangle();<br />
rect.DrawXORRectangle(g, X1, Y1, X2, Y2 );<br />
}<br />
<br />
void MainForm_Paint(object sender,<br />
System.Windows.Forms.PaintEventArgs e)<br />
{<br />
<br />
using (Graphics g = Graphics.FromHwnd(this.Handle))<br />
{<br />
g.Clear(this.BackColor);<br />
if (haveRect)<br />
{ <br />
RubberRectangle(g, XDown, YDown, oldX, oldY);<br />
}<br />
}<br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
MessageBox.Show("err yty");<br />
this.Invalidate();<br />
} <br />
} <br />
<br />
public enum PenStyles<br />
{<br />
PS_SOLID = 0,<br />
PS_DASH = 1,<br />
PS_DOT = 2,<br />
PS_DASHDOT = 3,<br />
PS_DASHDOTDOT = 4<br />
}<br />
public class RubberbandRectangle<br />
{<br />
private int NULL_BRUSH = 5;<br />
private int R2_XORPEN = 7;<br />
private PenStyles penStyle;<br />
private int BLACK_PEN = 0;<br />
<br />
public RubberbandRectangle()<br />
{<br />
penStyle = PenStyles.PS_DOT;<br />
}<br />
<br />
public PenStyles PenStyle<br />
{<br />
get { return penStyle; }<br />
set { penStyle = value; }<br />
}<br />
<br />
public void DrawXORRectangle(Graphics grp,<br />
int X1, int Y1, int X2, int Y2)<br />
{<br />
IntPtr hdc = grp.GetHdc();<br />
<br />
IntPtr gdiPen = CreatePen(penStyle,<br />
1, BLACK_PEN);<br />
<br />
SetROP2(hdc, R2_XORPEN);<br />
<br />
IntPtr oldPen = SelectObject(hdc, gdiPen);<br />
<br />
IntPtr oldBrush = SelectObject(hdc,<br />
GetStockObject(NULL_BRUSH));<br />
<br />
Rectangle(hdc, X1, Y1, X2, Y2);<br />
<br />
SelectObject(hdc, oldBrush);
SelectObject(hdc, oldPen);<br />
DeleteObject(gdiPen);
<br />
grp.ReleaseHdc(hdc);<br />
}<br />
<br />
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
private static extern int SetROP2(<br />
IntPtr hdc,
int enDrawMode
);<br />
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
private static extern IntPtr CreatePen(<br />
PenStyles enPenStyle,
int nWidth,
int crColor
);<br />
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
private static extern bool DeleteObject(<br />
IntPtr hObject
);<br />
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
private static extern IntPtr SelectObject(<br />
IntPtr hdc,
IntPtr hObject
);<br />
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
private static extern void Rectangle(<br />
IntPtr hdc,
int X1,
int Y1,
int X2,
int Y2
);<br />
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]<br />
private static extern IntPtr GetStockObject(<br />
int brStyle
);<br />
<br />
private static int RGB(int R, int G, int B)<br />
{<br />
return (R | (G << 8) | (B << 16));<br />
}<br />
}<br />
}<br />
<br />
|
|
|
|
|
Hi,
what is it that would make it impossible to do all painting in a Paint handler ?
you can have one Rectangle (say rubberRect) and one boolean class member
(say showRubberRect), have your mouse handlers modify those variables AND call
Invalidate(), and have your Paint handler paint the rubber band (if showRubberRect
is true). That would be a clean approach that follows both rules; and it would work.
About fancy XOR drawing: if you manage to do it in a mouse handler, you could
do it also in a Paint handler.
For the kind of things you want to achieve, it may be wise to set up a
double-buffering scheme.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
T.D.Prasad wrote: If I use Invalidate() method it is completely erasing the rubberband rectangle.
I thought you posted code yesterday where you drew your rubberband in your paint event. I recall telling you that you needed to, then changing my answer when I saw that you were.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
In the code that I have attached to my previous message I used Invalidate method inside button click event hadler(after messagebox.show statement). If I remove this statement partial rectangle is visible. if I keep it thewhole rectangle is erased after I close the MessageBox.
When I minimise and then maximise, then also rectangle is erased. I am not able to find a solution to this problem and breaking my head since yesterday. Any help to overcome this problem willbe highly appreciated.
Regards,
Prasad
|
|
|
|
|
I'm trying to have the value in a numeric up down highlight when selected by tab (for faster modification of the value). Currently it inserts at the beginning of the value. Anyone know if this is possible?
|
|
|
|
|
Hi, add an Enter handler with this content:
numericUpDown1.Select(0, numericUpDown1.Value.ToString().Length);
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Is there anyway to do this without referencing all of the numeric up downs, i have about 7 on one form and would like some way (without doing everyone individually) to do this. Thanks for your help!
|
|
|
|
|
Hi,
yes, for all events, if you add a handler programmatically
say with someEvent+=new EventHandler(myHandler);
you can specify the same handler over and over.
if you add a handler through Visual Designer, you can also choose the handler's
name.
And if that handler then needs to differentiate based on the specific control,
it should investigate its first argument ("object sender").
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi.
I'm writing an application that it connect to a SQL Server 2000 database. For testing I have 2 PC running Windows XP and in one of them I'm running SQL Server 2000.
When I run the application in the same PC where SQL is running the application works fine, but trying to connect from another PC it throws an exception connecting to the database. This is what I have:
My connection string:
string source = "Server = DEC-DEMIAN; Database = Security; User ID = Terminal2;" +<br />
"Password = 123; Trusted_Connection = False;";
Trying to connect from another PC it fails, thowing: "...SQLException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding".
I can't figure out what I missed to configure in SQL Server to be able to get remote connections. I have checked Server Properties -> Connections in SQL and it's ok.
Any help will be apreciatte.
Thankx
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
On the server, have you enabled named pipes? I have had that same problem before, and It was because I didn't enable named pipes.
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
I don't know.
Where should I find the "named pipes"??.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
I don't quite remember, Google it.
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
These specify the time, in seconds, to wait for the server to respond before generating an error. The default value is 15 (seconds).
"Connect Timeout=10;"
-or-
"Connection Timeout=10;"
|
|
|
|
|