|
|
Hi,
Maybe this is what you need:
.NET has a Region class that represents an arbitrary closed shape.
And Region.IsVisible() tells you whether a point, rectangle, whatever lies inside
the region.
BTW: if yours happens to be a web app, then PolygonHotSpot Class might be useful.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi, it is really great solution, but I don’t think it will work for polygon....
|
|
|
|
|
faheem424 wrote: it is really great solution, but I don’t think it will work for polygon....
Why not? Have you tried? What was the result?
|
|
|
|
|
I tried it and it is really working fine. It is good solution. You have really solved the looping cost of my program. Thanks a lot.
Regards,
|
|
|
|
|
you're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi Guys
I finnaly got the label.text to scroll (threading issue)! Now ive come across two other issues
1) is there some way i can check whether all the text in my label is displayed? The point is to only scroll the text if the labels size isnt big enough to show it all.
2) when the label is too small to show all the text and it scrolls it doesnt disply half words... (hope that makes sence) it will wait until theres enough space at the end before displaying the next word. So is there a way to make it kick this habbit cuz its making the text jurk every time a new word comes out? i want it to display the half word at the end cuz it scrolls and the rest of the word will be displayed eventually
thanx peepZ
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
|
|
|
|
|
You can use MeasureString on the graphics class to find out how big a string is with a given font, then compare with the label size.
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 )
|
|
|
|
|
thanx man, would u mind giving me an example? i havnt used and graphics or drawing classes like ever.
thanx again
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
|
|
|
|
|
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!
|
|
|
|