|
Hello,
This[^] article will give you an idea how to use "MeasureString" of the Graphics object.
It also shows you the usage of "DrawString" which you could use in your own LabelControl, to be more dynamic.
All the best,
Martin
|
|
|
|
|
thanx man, ill look into it
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
|
|
|
|
|
heres what i got
public partial class StatusBar : UserControl
{
Graphics g = new Graphics();
public void scrollText()
{
if (g.MeasureString(Message, lblMessage.Font) > lblMessage.Width)
{
}
else
{
}
}
}
the errors i get is
1) The type 'System.Drawing.Graphics' has no constructors defined
2) Operator '>' cannot be applied to operands of type 'System.Drawing.SizeF' and 'int'
i get why 2) is wrong cuz g.MeasureString() returnes 'SizeF' and im trying to compare that with int. how ever i dont get why 1) moans?
any ideas on how to rectify this?
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
|
|
|
|
|
Hello my quick friend,
You get the Graphics object of any Control for free in the OnPaint method.
If you inherit a control you can overridfe the OnPaint method and use the Graphics object of the passed args.
I show you an example where I inherited from Forms.Label:
private bool testsize = false;
public void TestSize()
{
testsize = true;
Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
if(testsize)
{
SizeF actSize = e.Graphics.MeasureString(Text, Font);
if(Width < actSize.Width)
{
MessageBox.Show("Error: label to slim");
}
testsize = false;
}
base.OnPaint (e);
}
You can start the test from outside by calling the "TestSize" method of the Label
Hope it helps!
All the best,
Martin
|
|
|
|
|
you rock dude!
i got it working by using the OnPaint method to check wheather its necicary to scroll and the my scroll() only does the deed if the flag is true!
thanx so much!
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
|
|
|
|
|
Glad I could help!
You are allways wellcome!
It's refreshing and makes fun helping you!
All the best,
Martin
|
|
|
|
|
Hi...
My requirement is to retrieve the child form values into parent form in windows application.
For this I am using delegate .
And i m getting the following error:
" An unhandled exception of type 'System.NullReferenceException' occurred in Delegates.exe
Additional information: Error binding to target method. "
Please give me the solution if anyone knows . Its urgent.
Code which I have written is:
Parent Form:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Delegates
{
public class Form1 : System.Windows.Forms.Form
{
private string str;
public string strPro
{
set
{
str=value;
}
get
{
return str;
}
}
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public void fncForm1Test()
{
textBox1.Text="Hi";
}
private void button1_Click(object sender, System.EventArgs e)
{
Form2 obj2=new Form2();
obj2.Owner=this;
obj2.ParentMain = (Form)this.Owner;//Giving ownership ePCRCustomizeControl page to Main page
obj2.HostForm = this;//Giving ownership ePCRCustomizeControl page to ePCR_BtnCompositeControl page
obj2.Show();
}
}
}
Child Form:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Delegates
{
public class Form2 : System.Windows.Forms.Form
{
public delegate void MyDelegate();
private Form _Parent;
public Form ParentMain
{
get
{
return _Parent;
}
set
{
_Parent = value;
}
}
private Form _Host;
public Form HostForm
{
get
{
return _Host;
}
set
{
_Host = value;
}
}
public Form2()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void button1_Click(object sender, System.EventArgs e)
{
MyDelegate obja;
//Form1 objForm1=new Form1();
Form1 objForm1=(Form1)_Parent;
obja=new MyDelegate(objForm1.fncForm1Test);
obja();
this.Hide();
objForm1.Owner=this;
//objForm1.Parent=
//objForm1.ShowDialog();
}
}
}
your
peter
|
|
|
|
|
peter rankel wrote: Please give me the solution if anyone knows . Its urgent.
Of course it is...
But not enough for you to post some code that points out the exact error, instead of the whole project ?
peter rankel wrote: obja=new MyDelegate(objForm1.fncForm1Test);
obja();
This is weird code, what is it trying to achieve ?
peter rankel wrote: Form1 objForm1=(Form1)_Parent;
As far as I can see, you should make _Parent an instance of Form1, instead of assuming it is and then trying to cast it.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Actually i m binding the values fetched from SQL server to dataset and displaying in datagrid. if this data grid consist of any date fields (by default mm/dd/yyyy), then it has to be displayed in "dd-MMM-yyyy" format to the user in datagrid..........
for (int i=0;i<ds.Tables[0].Rows.Count;i++)
{
if (ds.Tables[0].Rows[i]["Check"].ToString()!="")
{
DateTime dt=DateTime.Parse(ds.Tables[0].Rows[i]["Check"].ToString());
string fff;
fff=dt.ToString("dd-MMM-yyyy");
ds.Tables[0].Rows[i]["Check"]=fff;
ds.AcceptChanges();
} }
The above process is not updating in ds.tables[0].rows[i]["Check"]...
Help me plz...
modified on Thursday, February 14, 2008 12:54 AM
|
|
|
|
|
In your example, you're setting the column "kickoff", so the column "check" is not being updated. Could that be part of the problem?
Why not just format the date in the gridview at display time?
< - S
50 cups of coffee and you know it's on!
|
|
|
|
|
Thanks for your reply.
Actually I am trying to update in dataset so that we can bind any of the controls like (datagrid,gridview,etc.,)
Waiting for reply.....
|
|
|
|
|
But you don't need to update the dataset. If you already have the date in a column in the datatable, you just need to format it to dd-MMM-yyyy when displaying it in each control. (DataGridTableStyle and GridColumnStyle).
I think what you're trying to do, based on your code sample, is to add a new column to the table with the formatted date. Correct?
Just make sure the new column is a text column and not a date, and then bind to the new column and it should work.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
thanks my friend!
Can you just find if there is any way to update a date(usual format is 'MM/DD/YYYY', but i need format like 'DD-MMM-YYYY') field in dataset.
i.e, UPDATING 5/21/1984 TO 21-MAY-1984 WITHIN DATASET
THANKS IN ADVANCE
|
|
|
|
|
DateTimes aren't stored as "text" in memory. They are stored as the number. See here: http://msdn2.microsoft.com/en-us/library/system.datetime.aspx[^]
I know you just want a quick and easy answer, but I'm trying to help you understand that you already have the data you need, you just need to format it when you display it in the control. 5/21/1984 and 21-MAY-1984 are the same date, and represented by the same "number" in memory.
But, if you really need to store the formatted version of that number in the datatable do something like:
ds.Tables[0].Columns.Add("FormattedCheck", typeof(string));
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows[i]["Check"].ToString() != "")
{
DateTime dt = DateTime.Parse(ds.Tables[0].Rows[i]["Check"].ToString());
ds.Tables[0].Rows[i]["FormattedCheck"] = dt.ToString("dd-MMM-yyyy");
}
}
Then bind the column to "FormattedCheck" instead of "Check" in your DataGrid.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Thanks Steve, it helps me a lot and working fine.
But the thing is here all the fields fetching from database are dynamic (in the sense, user have provision to select the fields in order, so that if user specify the "check" field in a specified place (say, 4th column), then the "FormattedCheck" is to be placed in the same 4th column. could u
help me plz?
thanks in advance.
john
|
|
|
|
|
Ah, I see you updated your code. The column "Check" is probably of type DateTime, so when you set your formatted string value, it gets parsed back into a DateTime.
You can either add a new column to table[0] of type text and set the formatted date time to it (I don't recommend doing it this way), or look into a way of making the control format the existing datetime column (recommended).
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Please try to use an ISO 8601 compliant format YYYY-MM-DD.
|
|
|
|
|
Hi all,
I am developing a calendar application in C# that will require to store certain data (like date events, calendar style and some other preferences)in a database.
My preference will be MS SQL 2005 (though could be MySQL, or similar), however I wish to know if I was to use MS SQL 2005, could I include some dlls or other resource in the install of the application, purely for the application to run, without having to install another copy of MS SQL 2005 in the client PC? Like a cut down version of MS SQL 2005 as client site install? Otherwise I may have to go for MySQL or MS Access 2003, to avoid extra cost of the application.
Any ideas an suggestions are welcome.
Thanks in advance.
Alain
|
|
|
|
|
You can go with Express, which needs to be installed, or Compact, which is basically a few dlls.
|
|
|
|
|
|
|
hey there
this is a brige ill hav to cross in a few months... will sql server compact or express work for a db with over 80 tables that will grow like crazy? and can it be made to install with my application?
Thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
|
|
|
|
|
well, sql server ce and sql server express will definitely work with more than 80 tables.
using ce or express depends on what you mean with "grow like crazy".
even sql server express is limited to 4gb db size (http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx).
if you have hundreds of thousand data rows, you'll probably consider using sql server express instead of ce.
i don't know how complicated it will be to deploy sql server express with your application automatically,
but with sql server ce it can be quite easily done with clickonce deployment
|
|
|
|
|
well im in the time and atendance industry.
some of our clients have over 3000 employees that would clock maby 4 - 6 times a day (each clocking becomes a record) so that could potentially mean 18000 records added to the db per day!
and thats just one of the tables... what do you recomend?
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
|
|
|
|
|
well, in this case i don't think you will use sql server ce for this scenario.
if you want to stick with microsoft products and don't want to spend money on license costs,
you should pick sql server express.
but keep in mind that db size is limited to 4gigs.
|
|
|
|