|
Thanks for your answer.
PIEBALDconsult wrote: CodeDom should be calling the latest installed version of the compiler.
It should but did not. Anyway I was given a working solution on another forum.
Dictionary<string, string> options = new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } };
Microsoft.CSharp.CSharpCodeProvider cp = new Microsoft.CSharp.CSharpCodeProvider(options);
Obviously, instead of v3.5 you can specify any other supported version.
|
|
|
|
|
|
i would like to know to capture 'any' click event outside the custom TextBox control.
but not use lostfocus, mousehover, mouseout, etc, etc
i stumbled over this, afterr seeing this in other control from this page.
but they use it different.
kind regards
public partial class exTextBox : TextBox
{
protected exTextBox parent;
public exTextBox Parent
{
get { return parent; }
}
public exTextBox()
{
InitializeComponent();
TextBoxParent(this.parent);
}
public void TextBoxParent(exTextBox parent)
{
parent.Click += new EventHandler(parent_Click);
}
void parent_Click(object sender, EventArgs e)
{
MessageBox.Show("click", "click", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
--------------------------------------------------------------
errro: Object reference not set to an instance of an object.
public exTextBox()
{
this.Parent.Click +=new EventHandler(parent_Click);
}
void parent_Click(object sender, EventArgs e)
{
MessageBox.Show("click", "click", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Bad = knowing 2 much
modified on Wednesday, September 23, 2009 3:46 PM
|
|
|
|
|
The Parent property isn't set until the handle for the control is created AFAIK.
Try creating the event handler in an overrided OnHandleCreated method. This works for me.
using System;
using System.Windows.Forms;
namespace TestApp
{
public partial class Form1 : Form
{
ExtendedTextBox extendedTextBox1;
public Form1()
{
InitializeComponent();
extendedTextBox1 = new ExtendedTextBox();
Controls.Add(extendedTextBox1);
}
}
public class ExtendedTextBox : TextBox
{
public ExtendedTextBox()
{
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
Parent.Click += new EventHandler(Parent_Click);
}
void Parent_Click(object sender, EventArgs e)
{
MessageBox.Show(
"click",
"click",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
}
|
|
|
|
|
hey, thanx
indeed, i copy this to a new project, it works fine.
but when i copy the following lines to my old project,it's doesn't.
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
Parent.Click += new EventHandler(Parent_Click);
}
void Parent_Click(object sender, EventArgs e)
{
MessageBox.Show(
"click",
"click",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
the extended Textbox class gets compiled to dll.
Bad = knowing 2 much
|
|
|
|
|
this is the whole class
somehow 'SendMessage(...)' blocks it.
move the 'MessageBox' 2 lines higher @ 'protected override void OnHandleCreated' and it gets triggered.
put it baack below and it doesn't
public partial class exTextBox : TextBox
{
public exTextBox()
{
SendMessage(this.Handle, EM_SETCUEBANNER, 0, this.WaterMarkText);
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
//this.Parent.Click +=new EventHandler(Parent_Click);
Parent.Click += new EventHandler(Parent_Click);
// just for testing
MessageBox.Show(
"OnHandleCreated",
"OnHandleCreated",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
void Parent_Click(object sender, EventArgs e)
{
MessageBox.Show(
"click",
"click",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
#region Attributes
//[DefaultValue(typeof(String), "set the default value"), Category("Appearance"), Description("Set the default value.")]
private const int EM_SETCUEBANNER = 0x1501;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern Int32 SendMessage
(IntPtr hWnd, int msg, int wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
private string _waterMarkText = "Water Mark";
public string WaterMarkText
{
get { return _waterMarkText; }
set
{
SendMessage(this.Handle, EM_SETCUEBANNER, 0, value);
_waterMarkText = value;
Invalidate();
}
}
#endregion
public bool notempty()
{
if ((this.TextLength > 0) && (this.Text != this.WaterMarkText))
{
base.BackColor = Color.White;
return true;
}
else
{
base.BackColor = Color.Red;
this.Text = this.WaterMarkText;
return false;
}
}
}
Bad = knowing 2 much
|
|
|
|
|
HI all,
I am trying to create a crystal report to display some images..
But i need to display more than one image in a single page.. The number of images to be display per page will be given dynamically.
|
|
|
|
|
Are you talking about Resampling an image in your report based on Parameter value???
I dont know if Crystal Report has this functionality.
Why dont you do resampling in C# and then send those to Crystal Report ??
|
|
|
|
|
Hi all,
I do a lot of searching on CodeProject and other websites. Sometimes I download a demo project or sourcefiles to see the code and try to understand it...
I have a lot an error when I want to open such a demo:
"The application for project 'filepath\projectname.csproj is not installed. Make sure the application for the projectype (.csproj) is installed."
Does anyone knows how to solve this? I
Hope that anybody can explain me the reason and solution why it won't open...
Thx!
|
|
|
|
|
Hi,
there are lots of programming languages and development environments around. However most CP articles are based on Visual Studio, which exists in different flavors. The professional or team versions can open project and solution files for C, C++, C++/CLI, C# and VB.NET; the express versions are language-specific and free, so you may have to install a couple of them.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi Luc,
So you I just should install C# Express to open these files? Strange that VS can't open them. I'll give it a try.
Grts from Aalst,
Stieven
|
|
|
|
|
Before installing anything, try these two:
(A) double-click the file in Windows Explorer;
(B) open the Visual Studio versions you have, and let them open an "existing project".
Chances are (1) your file associations have not been set/have been lost, and/or (2) the versions are different and some conversion is needed, which VS will signal when trying (B).
If all this fails, download and install the latest VS C# Express.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi Luc,
Option B worked
Thx for the help!
Grts,
Stieven
|
|
|
|
|
hello,
I am using Visual c# 2005 and sql server2005
In my project I have to use the next date from the current system and have to use it in the where clause of sql query string for that i did the following:
string day = (DateTime.Now.AddDays(1).Day.ToString());
string month = (DateTime.Now.Month.ToString());
string year = (DateTime.Now.Year.ToString());
string date_nextDay = month + '/' + day + '/' + year;
then in sql query my code looks like this:
strQueryString = "select * from view_reservation where date =" + date_nextDay.ToString();
but the problem is sql is not recognizing it although there are some rows in database and whenever I just write the next day date in single quotes by myself it works correctly.Dont kno what to do
|
|
|
|
|
0) You need apostrophes if you do it that way.
1) Why not use System.DateTime.Now.AddDays(1).ToString( "MM'/'dd'/'yyyy" ) ; ?
2) Use a parameterized query and pass in the DateTime rather than making a string that will then have to be parsed.
|
|
|
|
|
strQueryString = string.Format("select * from view_reservation where date = '{0:M/d/yy}'", DateTime.Today.AddDays(1));
Note that the {0:...} part is using curly brackets... string.Format will replace that part with the first additional parameter (Parameter #0), using the format specified. So basically, it'll take Today + 1, format it in the "M/d/yy" form (ex. 9/23/09), and stick it into the string in the right spot.
Also note the single quotes around it... Most databases will require you to put dates inside single quotes.
|
|
|
|
|
In the format for a DateTime, the '/' doesn't mean '/', it means to use the date separator that's set in the operating system, which could be '-' (as it is on my system) or even '.'.
ISO 8601 specifies the use of '-'.
Control panel | Regional and Language Options | Regional Options | Customize | Date | Date separator
|
|
|
|
|
You have alread had the correct answers, about using quotes or better still parameterised query, but you will not always get tomorrow - you add 1 to the day part only. What happens on the last day of the month (or year) - 31st December 2009 will become 1st December 2009 using your code.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
He's using the AddDays method so that's taken care of by the framework - so long as he doesn't try to add to DateTime.MaxValue he'll be OK.
|
|
|
|
|
Only for the day; not for the month and year.
|
|
|
|
|
right now DateTime.Now.AddDays(365+30+1).ToString() returns 25-Oct-2010 1:11:42 on my system.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
The OP added a day when accessing the day, but not when accessing the month and year.
|
|
|
|
|
You're right of course.
And he shouldn't use multiple DateTime.Now calls anyway, it may fail around midnight.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
But he is only adding to the day variable:
string day = (DateTime.Now.AddDays(1).Day.ToString());
string month = (DateTime.Now.Month.ToString());
string year = (DateTime.Now.Year.ToString());
string date_nextDay = month + '/' + day + '/' + year;
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Ah... I saw the AddDays method and assumed that he would be using the returned DateTime instance so didn't look any more at the code.
Using three DateTime instances to create the string representations of a date's constituent parts is a WTF that I wasn't expecting!
|
|
|
|