|
I want to create a hatch brush using as hatch style a string ... for example "BackwardDiagonal"
how can I do something like :
HatchBrush hb = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Red);
using only the string "BackwardDiagonal" ?
modified 30-Nov-21 21:01pm.
|
|
|
|
|
Well, you could either use Reflection (I haven't done this myself), or you would need to parse your string in the constructor:
public HatchBrush(string type, Color color)
{
switch(type)
{
case "BackwardDiagonal":
return new BackwardDiagonalBrush(...);
default:
return new SomeDefaultBrush(...);
}
}
However, this isn't as flexible as the Relfection approach
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
with switch and case it would take some time because I want to have multiple choices (over 10 or 20)
I'll consider finding more about Relfection .
Thanks a lot.
modified 30-Nov-21 21:01pm.
|
|
|
|
|
You can use Enum.Parse to do this
HatchBrush b = new HatchBrush((HatchStyle)Enum.Parse(typeof(HatchStyle),"BackgroundDiagonal"),Color.Gray,Color.LightGray);
|
|
|
|
|
Problem solved
Thanks a lot.
modified 30-Nov-21 21:01pm.
|
|
|
|
|
Why do I get an error saying "Input string was not in correct format" when I do the following?
sb.AppendLine(string.Format("\t\t\tpublic static string {0}TableName { get { return \"{0}\"; } }", tr.TABLE_NAME));
sb is a stringbuilder
tr.TABLE_NAME is a string
I'm thinking that it is probably something to do with the curly braces in there, almost like it expects a date format string or something in there.
I know the code is ugly, but it's just for a little quick utility.
|
|
|
|
|
Apparently, you have to escape a single "{" with another "{". You also have to do this with the closing braces.
|
|
|
|
|
Well, it's definitely the curly braces. That's confusing the Format method. When you want to put a '{' in the string use '{{'.
Logifusion[^]
|
|
|
|
|
Hi.
I'm new to C# but want to learn.
Can someone tell me how to implement (where to enter code mentioned below) a single process instance object that I found on:
http://www.codeproject.com/csharp/cssingprocess.asp?&forumid=11773
I can make that work, but then I don't see title bar of my program, so I'm sure I'm missed up somewhere
Thanks in advance.
|
|
|
|
|
I'm not sure where your problem is. Create a new windows application project in visual studio. Download the code that goes with the article you have. It's a CS file. Add that to your project. Make sure the namespaces are the same. Look in the Form1 code and find the Main method and add the following (as detailed in the article):
using(SingleProgramInstance spi = new SingleProgramInstance())
{
if (spi.IsSingleInstance)
{
Application.Run(new Form1());
}
else
{
spi.RaiseOtherProcess();
}
}
Logifusion[^]
|
|
|
|
|
I want to check the input to a text box is numeric (e.g., mmddyyyy). Is there a command for this?
sas
|
|
|
|
|
If you're using framework 2.0 you could use DateTime.TryParse or the MaskedTextBox . Otherwise use DateTime.Parse .
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
Int.TryParse
Will return true if the string is a number
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hello again all. I found an example of a fully editable datagrid that was attached to the Northwind database. I have been tinkering with it to use with my own data. The code uses the Microsoft SQL Helper.cs class.
Originally the code opened the page, and returned all the employees in the NW database. I ran the project and everything was fine.
Original code:
private void BindData()<br />
{<br />
ds = new DataSet();<br />
Session["ds"]=ds;<br />
dt = ds.Tables[0];<br />
Session["dt"]=dt;<br />
DataGrid1.DataSource=dt;<br />
DataGrid1.DataBind();<br />
<br />
}
I changed it to take a parameter. The user enters a part number in a text box, and clicks a search button and then I want the datagrid to populate. It returns 3 blank rows. When I went through the debugger it looks like it tries to run through the SQLHelper code before it looks at the button click function.
I think it has to do with how I'm sending the parameters but I'm not sure because if I change the stored procedure and code for no parameters, it works.
Current code:
private void BindData()<br />
{<br />
strPartNumberInputReference = txtSearchPart.Text;<br />
ds = new DataSet();<br />
SqlParameter param = new SqlParameter("@PartID", strPartNumberInputReference);<br />
ds=SqlHelper.ExecuteDataset(this.connectionString, CommandType.StoredProcedure, "dbo.GetPartInfoTest", param);<br />
Session["ds"]=ds;<br />
dt = ds.Tables[0];<br />
Session["dt"]=dt;<br />
dgParts.DataSource=dt;<br />
dgParts.DataBind();<br />
txtSearchPart.Text = "";<br />
<br />
}
Does anyone have any ideas? I didn't post the SQLHelper code as it is LONG but if someone is willing to help and needs it let me know.
Thanks again to all who help!
|
|
|
|
|
So it looks like changing the ExecuteDataset() call resolved your previous problem?
leckey wrote: if I change the stored procedure
Did you test the sp with the parameter in your Database environment?
|
|
|
|
|
Yes, changing the ExecuteDataset to use Command.StoredProcedure got rid of the previous error.
I did test the sp with a parameter.
SP with parameter:
CREATE PROCEDURE [dbo].[GetPartInfoTest]<br />
@PartInfo varchar<br />
<br />
AS<br />
SELECT * FROM Parts<br />
GO
BindData with parameter:
private void BindData()<br />
{<br />
strPartNumberInputReference = txtSearchPart.Text;<br />
ds = new DataSet();<br />
SqlParameter param = new SqlParameter("@PartID", strPartNumberInputReference);<br />
ds=SqlHelper.ExecuteDataset(this.connectionString, CommandType.StoredProcedure, "dbo.GetPartInfoTest", param);<br />
<br />
Session["ds"]=ds;<br />
dt = ds.Tables[0];<br />
Session["dt"]=dt;<br />
dgParts.DataSource=dt;<br />
dgParts.DataBind();<br />
txtSearchPart.Text = "";<br />
<br />
}
DataBind without parameter
private void BindData()<br />
{<br />
strPartNumberInputReference = txtSearchPart.Text;<br />
ds = new DataSet();<br />
SqlParameter param = new SqlParameter("@PartID", strPartNumberInputReference);<br />
ds=SqlHelper.ExecuteDataset(this.connectionString, CommandType.StoredProcedure, "dbo.GetPartInfoTest");<br />
Session["ds"]=ds;<br />
dt = ds.Tables[0];<br />
Session["dt"]=dt;<br />
dgParts.DataSource=dt;<br />
dgParts.DataBind();<br />
txtSearchPart.Text = "";<br />
<br />
}
|
|
|
|
|
The problem might be that your SP declares the parameter as @PartInfo, but you are creating an SqlParameter whose Name is @PartID.
|
|
|
|
|
Okay, got my names matching.
I commented out the BindData call in th Page_Load
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
<br />
if(!Page.IsPostBack)<br />
{<br />
}<br />
<br />
}
So now I don't get three blank lines. But I don't get the data to return either. So I think my problem is how I'm setting up the page_load.
|
|
|
|
|
leckey wrote: I commented out the BindData call in th Page_Load
You have to call BindData() to get the Grid binding to execute. Also since this is a ASP.NET environment you might get more help in that forum.
|
|
|
|
|
I wasn't implying that another call to BindData() would be problematic. It was just a way of explaining why the SqlHelper method was executing before the Button's Click handler. Without that call in Page.Load, I wouldn't expect the grid to show any data because that call is what initially populates it.
Josh
|
|
|
|
|
leckey wrote: When I went through the debugger it looks like it tries to run through the SQLHelper code before it looks at the button click function.
Perhaps some other code in your app is calling SqlHelper methods too.
I assume that your BindData method (or the SqlHelper method) is being called from somewhere else in the application. You can do a global search in Visual Studio (hit Ctrl + Shift + F10) and search for DataBind or SqlHelper. See what you come up with. Alternatively you can set a breakpoint in the SqlHelper method, run in Debug mode, and when the breakpoint is hit you can check the Call Stack window to see what method called it.
If there is such a thing as Hell, it appears that you have entered it.
Cheers,
Josh
|
|
|
|
|
hello im using the graphics class to draw some stuff on a form.
Graphics Draw = this.form1.CreateGraphics();
Draw.FillEllipse(Brushes.Red, Circles);
something like that. But once the graphic is drawn and i move another form over, it disappears. so how can i keep my graphic display all the time.
Thank you
Donkaiser
|
|
|
|
|
You could create an image, get the graphics context off of the image, and draw it there. Then just keep that image up on the form.
Logifusion[^]
|
|
|
|
|
do you have an example? I know the logic but im sure C# has some class that will take care that.
and by image u mean a bitmap image or jpg image.
Donkaiser
|
|
|
|
|
Absolutely. Take your form and add a PictureBox control to it. Then in your constructor you can do this:
this.pictureBox1.Image = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
Graphics g = Graphics.FromImage(this.pictureBox1.Image);
g.FillEllipse(Brushes.Red, 5, 5, 50, 50);
You don't have to set anything on PictureBox, just put it on the form.
Logifusion[^]
|
|
|
|