|
The default constructor for the Random class uses the system clock to seed the random number generator. Your code is running fast enough that the system clock has not changed between calls to the constructor, resulting in the same random numbers being generated each iteration. See the MSDN documentation for the Random constructor[^] for more clarification and a good example.
|
|
|
|
|
I am newly started working on C# for web application. Not able to get Browse option in my application, to browse images and documents and upload it. guru
|
|
|
|
|
And what errors and/or difficulties are you facing?
Please provide the failing code..
|
|
|
|
|
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputFile File1;
protected System.Web.UI.WebControls.Button cmdUpload;
protected System.Web.UI.WebControls.Label lblMessage;
string sFileDir= "C:\";
long lMaxFileSize = 4096;
ERROR:-Error 28 Unrecognized escape sequence C:\Documents and Settings\guru\Desktop\Product implementation\Uplode.aspx.cs 24 36 C:\...\Product implementation\
At above bold line was casing problem. I am not able to understood this exception.guru
|
|
|
|
|
Use either "C:\\" or @"C:\" instead of "C:\" - the '\' character is an escape, so the compiler thinks you want to include a double quote character in your string rather than terminating it. You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
this small tip solved 90% my problem.
thnxguru
|
|
|
|
|
i want to make a software that should run as service
and as when as user send any type of print my software dialogs should be work
so please help me how i can capture print command for my software
Regards
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:38am.
|
|
|
|
|
this is defining to check printers and then commands
i want to trace print commmand
as when as user want to send print my work should start
|
|
|
|
|
You need to write a printer driver and set your 'device' as the default printer. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
it is very easy to detect if someone work with mouse move event of picturebox. but i want to detect mouse over picturebox in mouse move event of the form so first i did set the keypreview property of form to true and then i wrote the code in mouse move event of form.
so my code is ---
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
int X=e.X;
int Y=e.Y;
if ((X >= pic.Left && X <= pic.Left + pic.Width) && (Y >= pic.Top && Y <= pic.Top + pic.Height))
{
lblMsg.Text = "Mouse over picturebox";
}
else
{
lblMsg.Text = "";
}
}
this code is not working. where i am making the mistake. please rectify me.
i tried this with another approach like
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (pic.Bounds.Contains(PointToClient(new Point(e.X, e.Y))))
lblMsg.Text = "Mouse over picturebox";
else
lblMsg.Text = "";
}
please help me with sample code.
thanks in advancetbhattacharjee
|
|
|
|
|
Form.KeyPreview is all about keyboard input, not mouse actions. The latter always go to the active Control, not the Form containing it.
|
|
|
|
|
If you replace your code with
if (pic.Bounds.Contains(e.Location))
{
lblMsg.Text = "Mouse over picturebox";
}
else
{
lblMsg.Text = pic.Bounds.ToString() + ":" + e.Location.ToString();
}
You will see what the problem is:
The location only changes when the mouse is not over any control, and never becomes "Mouse over picturebox".
This is because the individual controls are expected to handle their own events, so they get the mouse move events instead of the form.
As stancrm said: handle it in the PictureBox MouseMove event instead.
Oh, and it is much easier to read if you use the Rectangle.Contains method, rather than write it in longhand - and less prone to errors too!You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Hi, I would solve the problem with handling of MouseEnter and MouseLeave events.
Example:
using System;
using System.Windows.Forms;
using System.Drawing;
namespace MouseOverPictureBox
{
static class Program
{
static void Main()
{
Form form = new Form();
PictureBox pb = new PictureBox();
pb.BackColor = Color.Red;
pb.MouseEnter += delegate(object sender, EventArgs e)
{
form.BackColor = Color.Green;
};
pb.MouseLeave += delegate(object sender, EventArgs e)
{
form.BackColor = SystemColors.Control;
};
form.Controls.Add(pb);
Application.Run(form);
}
}
}
|
|
|
|
|
I have an XMLDocuemt supplied by a 3rd party. I have an xpath expression checking for value for element "x". The problem is sometimes element "x" does not exist and im getting a error "bject reference not set to an instance of an Object".
How do i check if element x (using xpath) exist
|
|
|
|
|
Check for null the result of the XPath query before using the Value property.
|
|
|
|
|
Hi, I have an asp.net web application, I have read/write a word file with the help of openxml sdk. Now I need to convert that word file to a pdf format. Is there anyway to convert word file to pdf with the openxml sdk ? Pankaj
|
|
|
|
|
Ok Guys I'm facing a strange problem here, and I dunno if its a bug or I am doing something wrong.
Here's the code:
using System;
using System.Diagnostics;
using System.Net;
using System.Windows.Forms;
namespace ConsoleApplication
{
internal class Program
{
private static void Main(string[] args)
{
var webClient = new WebClient();
webClient.DownloadProgressChanged += (o, e) => Debug.WriteLine(e.ProgressPercentage);
webClient.DownloadFileCompleted += (o, e) => Debug.WriteLine("Download completed.");
Debug.WriteLine("Starting download...");
webClient.DownloadFileAsync(new Uri("http://cdimage.debian.org/debian-cd/5.0.4/i386/iso-cd/debian-504-i386-netinst.iso"), "debian-504-i386-netinst.iso");
Console.Read();
}
}
}
Everything works fine like this, events are raised normally.
Now try to uncomment the progressbar initialization and events will stop to be fired (I noticed the problem with the progress bar because I needed to add a progress bar dynamically to the form, dunno if there are other scenarios where this happens) even if the download proceeds normally.
Maybe is just me or maybe I have convinced myself this code is right that I cant no longer see where I epic fail.
Anyone having the same problem?
Thanks in advance.
Matt
|
|
|
|
|
Hi, this looks strange! I'd guess your problem in the example is Console.Read()... When I tried your code in an windows forms project there was no problem. Can you show your orignal code
Teuz wrote: (I noticed the problem with the progress bar because I needed to add a progress bar dynamically to the form, dunno if there are other scenarios where this happens)
|
|
|
|
|
Thank you for the reply.
How did you managed to make it work in a windows form project? This code acts exactly like the console one, no event are fired but the file is downloaded:
using System;
using System.Diagnostics;
using System.Net;
using System.Threading;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void CheckUpdate(object arg)
{
DownloadFile();
Thread.Sleep(5000);
Debug.WriteLine("Update completed");
}
public void DownloadFile()
{
var webClient = new WebClient();
var progressBar = new ProgressBar();
AddControl(progressBar);
webClient.DownloadProgressChanged += (o, e) =>
{
Debug.WriteLine(e.ProgressPercentage);
progressBar.Value = e.ProgressPercentage;
};
webClient.DownloadFileCompleted += (o, e) => Debug.WriteLine("Download completed.");
Debug.WriteLine("Starting download...");
webClient.DownloadFileAsync(new Uri("http://cdimage.debian.org/debian-cd/5.0.4/i386/iso-cd/debian-504-i386-netinst.iso"), "debian-504-i386-netinst.iso");
}
private void button1_Click(object sender, EventArgs e)
{
ThreadPool.QueueUserWorkItem(CheckUpdate);
}
private void AddControl(Control control)
{
if (flowLayoutPanel1.InvokeRequired)
flowLayoutPanel1.BeginInvoke(new MethodInvoker(() => AddControl(control)));
else
flowLayoutPanel1.Controls.Add(control);
}
}
}
This is also quite similar the code I'm actually using in my project. I forgot to mention that for this project I'm using NET 2.0 so maybe this can work differently in later versions.
|
|
|
|
|
please tell me Error in My Coding
My Coding Is
OdbcConnection conn = new OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};Dbq=D:\\Opal Agro Chemical\\OpalAgroChemical.mdb;Uid=;Pwd=;");
string Invqurey = "insert into invoice(id,date,gpno,product,customer,qty,carton,rate,amount,bilty,expdate) values('" + inid.Text + "','" + dt.Text + "','" + gpno.Text + "','" + prod.Text + "','" + cust.Text + "','" + qty.Text + "','" + carton.Text + "','" + rate.Text + "','" + amount.Text + "','" + bilty.Text + "','" + expdate.Text +"')";
OdbcCommand cmd = new OdbcCommand(Invqurey, conn);
conn.Open();
MessageBox.Show(cmd.CommandText);
cmd.ExecuteNonQuery();
conn.Close();
This Error Is Showing When i Insert Record
System.Data.Odbc.OdbcException was unhandled
Message="ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement."
Source="odbcjt32.dll"
ErrorCode=-2146232009
Please Help Me
Thanks In Advance
Jawad Khatri
|
|
|
|
|
Get rid of the problem, and potential SQL injection attacks by using Parameterized queries:
string Invqurey = "INSERT INTO invoice (id, date, gpno, product, customer, qty, carton, rate, amount, bilty, expdate)" +
" VALUES (@inid, @dt, @gpno, @prod, @cust, @qty, @carton, @rate, @amount, @bilty, @expdate)";
OdbcCommand cmd = new OdbcCommand(Invqurey, conn);
cmd.AddWithValue("@inid", inid.Text);
cmd.AddWithValue("@gpno", gpno.Text);
... Oh - and the standard is to use UPPERCASE for SQL keywords.You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
OriginalGriff wrote: Oh - and the standard is to use UPPERCASE for SQL keywords.
In every code shop and software house I've been in for over 20 years the standard has always been lower case! Don't want to start an argument, just saying that the real standard is that there are no real standards...Tychotics: take us back to the moon
"Life, for ever dying to be born afresh, for ever young and eager, will presently stand upon this earth as upon a footstool, and stretch out its realm amidst the stars."
H. G. Wells
|
|
|
|
|
get the content onv Invqurey, an ask then the question in the SQL forum.
|
|
|
|
|
Hi
I am trying to write a TypeConverter for SubProperties, in this case the BooleanConverter.
I managed to use the BooleanConverter with Bool-Fields that are MainProperties, but not with BoolProperties that are SubProperties.
I am using the Font-Property for my Controls, but I'd like to translate all the values in a different language.
But how is it possible to use the BooleanConverter (or something like it) for the Bool-Values inside the Font-Property (so for example for the SubProperty "Bold").
So I'd like to change the "Yes" and "No" in the DropDown Box for "Bold".
I hope you know what I mean/try to explain
Thanks in advance for your help
|
|
|
|