|
TextBox tb = sender as Textbox;
if (tb.Name == ...
|
|
|
|
|
Sorry, I amswer questions in several forums. The same logic applies, cast sender to the right type and you can get the name.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
<br />
TextBox box = sender as TextBox;<br />
box will then become the textbox that has fired the event, and you can handle it accordingly.
|
|
|
|
|
thanks this worked a treat.
Sorry about the delay other matters took up my time until now (2:13am - lol)
Cheers
|
|
|
|
|
Hiya guys!
I'm new to this forum, and new to C#, and have hit upon a snag in a project i'm working on.
I am trying to load an existing webpage into .net, and populate the fields on this page.
So far, I have created a new web form, and I can grab data from the DOM.
I have found the fieldnames that I want to populate, but I have no idea how to populate them!
It looks like the webpage is read only, as I cannot set any properties.
Can someone please point me in the right direction?
Sorry if its a simple question, but I have only started learning c# this week.
Thanks in advance!
DB
|
|
|
|
|
You can get quick response, if you will post into the right forum.
Like your question is related asp.net, so it should be post into the Asp.Net section not C#.
Parwej Ahamad
R & D with IIS 5.0/6.0
|
|
|
|
|
Hi Guys
I want to write a piece of code to automate a network printer installation on a vista client. I didn't found samples on the web with any possible solutions. I tried to use WMI but at this I have no solution for my problem
Every time when I run this code I habe an "Generic failure" when execute the printerObject.Put(options); method.
So I hope anyone of you can help me to find a reason to this issue.
Thanks in advanced.
Dany
Code:
public bool AddPrinter(string printerName, string printerDriver, string portName, bool sharedPrinter)
{
bool result = false;
try
{
//init Win32_Printer class
ManagementClass printerClass = InitClass("Win32_Printer");
SelectQuery selectQuery = new SelectQuery();
IPHostEntry iphe = Dns.Resolve(printerName);
string priterport = 9100.ToString() ;
//create new Win32_Printer object
ManagementObject printerObject = printerClass.CreateInstance();
//AddPrinterPort(portName, iphe.AddressList.GetValue(0).ToString(), priterport);
AddPrinterPort(portName, printerName, priterport);
if (portName == null || portName.Length == 0)
printerObject["PortName"] = "LPT1:";
else
{
//if (portName[portName.Length - 1] != ':')
// printerObject["PortName"] = (portName + ":");
//else
printerObject["PortName"] = portName;
}
//set driver and device names
printerObject["DriverName"] = printerDriver;
printerObject["DeviceID"] = printerName;
//set sharing
if (sharedPrinter)
{
printerObject["Shared"] = sharedPrinter;
printerObject["ShareName"] = printerName;
}
printerObject["comment"] = "Zeljko Philipp";
// specify put options: update or create
PutOptions options = new PutOptions();
options.Type = PutType.UpdateOrCreate;
//put a newly created object to WMI objects set
printerObject.Put(options);
result = true;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("WMI exception: {0}", ex.Message);
throw new Exception(String.Format("WMI exception: {0}", ex.Message));
}
return result;
}
|
|
|
|
|
I can't seem to find anything to help my desktop application load a website and pass through the current logged in user.
I know I can get the current logged in user by
string NTUsername = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
and I have seen posts where you can specify the Username in the URL but neither are working
url = "http://username:" + NTUsername + "@subdomain.domain.com/default.aspx";
I have even tried to hard code in my username/domain. Can someone help give me some insight on how to pass the current logged in user to the web browser control?
|
|
|
|
|
Brad Wick wrote: and I have seen posts where you can specify the Username in the URL
Well the site has to support that yes? Does it? You have to do whatever the site requires.
led mike
|
|
|
|
|
HI all,
I'm very confused about Static.
What is a exact defination of Static?
How it works?
Wht are the advantages/why & where we need it?
Waiting for reply
Thanks in advance
Ashwini
|
|
|
|
|
|
Even better, I've found a whole site with 645000[^] pages about it.
Simon
|
|
|
|
|
I call the below code from the MouseClick event of a control. However, it doesnt seem a good idea to be constantly creating gfx objects every time the user clicks the mouse.
private void ClickedEdge(Point mousePoint)
{
_selectedEdge = null;
Graphics gfx = this.CreateGraphics();
Rectangle clickedRect = new Rectangle(mousePoint, new Size(1, 1));
foreach (EdgeObj edge in _edgeItems)
{
Rectangle edgeRect = Rectangle.Round(edge.Region.GetBounds(gfx));
if (clickedRect.IntersectsWith(edgeRect))
{
_selectedEdge = edge;
break;
}
}
}
So, does anyone know of a better way to find out if the mouse has clicked on a line which has been drawn onto the control?
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Save the extents of all the primitives drawn (lines, rects, polygons) in a List, for example
List<Primitive> primitivesDrawn = new List<Primitive>();
with Primitive being an abstract class like this (just an example, can be done different):
public abstract class Primitive
{
public IEnumerable<Point> Points { get; set; }
public abstract bool Intersects(Point pt);
public abstract bool Intersects(Rect pt);
}
and some primitives like:
public class Line : Primitive;
public class Triangle : Primitive;
public class Rectangle : Primitive;
This data structure can be used for both drawing it to the control as well as doing intersection testing and much more.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
This could be so much more simple. The equation of a line: Y = mX + C X and Y are abvious m is the gradient and C is an offset.
So, if you can get the equation of your lines then you could use something like this:
void ClickedEdge(Point mousePoint)
{
if(mousePoint.Y == ( lineM*mousePoint.X +lineC))
}
Although you might want to check that mousePoint.Y is +/- 1 from the calculated Y position because its gonna be almost imposible to click the line exactly (since you can't click between pixels)
float Y = lineM*mousePoint.X +lineC;
Y = Y - mousePoint.Y;
Y *= Y;
if(Y <= 1)
To get the equation for your line:
m = (endY - startY)/(endX - startX);<br />
c = m*startX - startY;
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
modified on Friday, June 13, 2008 1:20 PM
|
|
|
|
|
SK Genius,
What is lineX? Below is what i have done from your suggestion.
int lineM = (edge.EndPoint.Y - edge.StartPoint.Y) / (edge.EndPoint.X - edge.StartPoint.Y);
int lineC = lineM * edge.StartPoint.X - edge.StartPoint.Y;
int lineX = 0;
if (mousePoint.Y == (lineM * lineX + lineC))
Trace.WriteLine("hit");
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Oops, not sure what i was thinking, that should just be mousePoint.X
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
SK Genius,
It doesn't seem to be working. The cal of lineM * mousePoint.X + lineC is just giving me tons of numbers that dont even come close to mousePoint.Y.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
This little test worked out:
PointF start = new Point(0, 0);
PointF end = new Point(150, 150);
float m;
float c;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawLine(Pens.Black, start, end);
}
void Form1MouseClick(object sender, MouseEventArgs e)
{
m = (end.Y - start.Y)/(end.X - start.X);
c = start.Y - m*start.X;
Y = m*e.X + c;
Y -= e.Y;
Y *= Y;
if(Y <= 5)
MessageBox.Show("Shwam");
}
Clicking within one pixel was hard(ish) 5 seems pretty good though.
Damn, I just remebered, the gradient for a verticle line would be infinite. That means that this wouldn't work for completely verticle lines.
EDIT: Although
m = (end.Y - start.Y)/(end.X - start.X);
c = start.Y - m*start.X;
Y = m*e.X + c;
Y -= e.Y;
if(-3 < Y && Y lt; 2)
MessageBox.Show("Shwam");
if(float.IsInfinity(m)) {
float X = start.X - e.X;
if(-3 < X && X < 3)
MessageBox.Show("Shwam");
}
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
We have this program(.exe) on the web where it is being downloaded by people, in the program they set their preferences. It is a program similar to Paint
The problem is that when they download a new version of our program and install it, they loose their personal preferences set in the older version. This facility was always working, till we got the new version of the program on the net.( I did it)
For the personal settings we have a file Profile.xml where all the settings get saved(in the folder bin\release and bin\Debug. We also have two other files Profile.xml_backup and ProfileInstaller.xml in the same folders which I am not sure what they do.
So guys would anyone know what changes do i have to make, and where so that the personal changes save in the new version of the program insatlled
|
|
|
|
|
I dont think I get you. You wrote this program, but you do not know how it works?
|
|
|
|
|
OK I am sorry for not being very clear. I just made a few changes to the already existing code(Bug fixes) made a new version(exe) and uploaded it on the internet.
There is also a class UserProfile.cs which is responsible for the Profile.xml file.(If that helps)
|
|
|
|
|
Sounds to me like you download Profile.xml with the new version. Also, why have the debug version available?
humayunlalzad wrote: This facility was always working, till we got the new version of the program on the net.( I did it)
Did you write it or is it a 3rd party app you are installing?
humayunlalzad wrote: We also have two other files Profile.xml_backup and ProfileInstaller.xml in the same folders which I am not sure what they do.
Have a look in them and see what they contain - probably some default settings at a guess.
Personally I would back up the profile.xml file and restore it after the new version is installed - of course, if it's a 3rd party app it may need some settings in the new file.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
The code was written in-house, but by the coders before me. We keep upgrading things, debugging the present program and upload. It is not a 3rd party app.
So how do you restore the backup of the profile.xml file in the new version thats what I want to know. We are using VS2005
And Thanx for taking the trouble
|
|
|
|
|
humayunlalzad wrote:
This facility was always working, till we got the new version of the program on the net.( I did it)
......
So guys would anyone know what changes do i have to make, and where so that the personal changes save in the new version of the program insatlled
I sort of assumed you had put the copy of a 3rd party app on the network for others to install, particularly when you asked "So guys would anyone know what changes do i have to make.."
As it is written in house and you have the source code why would anyone else know what to change? Just because someone else wrote it is no excuse, I have spent about 90% of my coding life working with other people's code (as have most professional coders), and you just have to work out whats being done.
I suggested backing up the profile and restoring it as a work around when I was under the illusion it was a bought in app. I would just do it as part of the install.
Bob
Ashfield Consultants Ltd
|
|
|
|