|
Whether you want to generate a dynamic function, write a dynamic algorithm or want to handle delegate inline, anonymous functions have always been at your service. However one area where in anonymous function lacking is, making a recursive call. Since it does not have function signature it’s not possible to make recursive call, at lease not directly. This article shows you how to achieve that.
See complete blog:
http://aamironline.com/blog/2006/10/29/recursive-call-with-anonymous-function.xml[^]
|
|
|
|
|
Why post this here? Why not make it into an Article? It seems like it would make an excellent article.
Arthur Dent - "That would explain it. All my life I've had this strange feeling that there's something big and sinister going on in the world."
Slartibartfast - "No. That's perfectly normal paranoia. Everybody in the universe gets that."
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
|
Hi everyone!
My problem is that i have a user control. It has an ArrayList, in the ArrayList there is a collection of Buttons. I can set up these Buttons at designtime, but when I go to run the program, it seems to clear out my arraylist.
Why would it do this? Am I missing some vital bit of code that is needed in the transition from designtime to runtime. The code I use is below. Any help would be appreciated.
the hbHoverButton is another control of mine, but I assume that its the same problem even if I change the control.
Thanks
<br />
using System;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Drawing;<br />
using System.Data;<br />
using System.Windows.Forms;<br />
<br />
namespace Toolbar<br />
{<br />
[ToolboxBitmapAttribute(typeof(Toolbar.tbToolbar), "tbToolbar.ico")]<br />
public class tbToolbar : System.Windows.Forms.UserControl<br />
{<br />
private System.Windows.Forms.Button cmdToolbar;<br />
private System.Windows.Forms.Panel pnlPanel;<br />
private System.ComponentModel.Container components = null;<br />
private HoverButton.hbHoverButton hbDefault;<br />
<br />
<br />
#region Variables<br />
private ArrayList alButtons = new ArrayList();<br />
private int mButtonHeight = 54;<br />
private string mToolbarText = "Toolbar";<br />
private ContentAlignment mButtonImageAlign = ContentAlignment.TopCenter;<br />
private ContentAlignment mButtonTextAlign = ContentAlignment.BottomCenter;<br />
private string mKey;<br />
#endregion<br />
<br />
<br />
#region Properties<br />
<br />
public Toolbar.clsHoverButtonProp[] ButtonItems<br />
{<br />
get<br />
{<br />
Toolbar.clsHoverButtonProp[] newImage = new Toolbar.clsHoverButtonProp[alButtons.Count];<br />
<br />
for(int i = 0; i < alButtons.Count; i++)<br />
{ <br />
HoverButton.hbHoverButton newHover = Button(i);<br />
newImage[i] = new Toolbar.clsHoverButtonProp();<br />
newImage[i].ButtonText = newHover.ButtonText;<br />
newImage[i].ButtonImage = newHover.ButtonImage;<br />
}<br />
<br />
return newImage;}<br />
set<br />
{<br />
alButtons.Clear();<br />
for(int i = 0; i < value.Length; i++)<br />
{<br />
Toolbar.clsHoverButtonProp newImage = new Toolbar.clsHoverButtonProp();<br />
newImage = value[i];<br />
<br />
HoverButton.hbHoverButton tbNewButton = new HoverButton.hbHoverButton();<br />
<br />
tbNewButton.ButtonText = newImage.ButtonText;<br />
tbNewButton.ButtonImage = newImage.ButtonImage;<br />
tbNewButton.Left = hbDefault.Left;<br />
tbNewButton.Width = pnlPanel.Width - 11;<br />
tbNewButton.ForeColor = Color.White;<br />
tbNewButton.Anchor = hbDefault.Anchor;<br />
tbNewButton.Visible = true;<br />
tbNewButton.Click += new EventHandler(HoverButton_Clicked);<br />
<br />
alButtons.Add(tbNewButton);<br />
<br />
}<br />
<br />
DisplayButtons();<br />
}<br />
}<br />
<br />
<br />
public int ButtonHeight<br />
{<br />
get { return mButtonHeight;}<br />
set <br />
{<br />
mButtonHeight = value;<br />
hbDefault.Height = mButtonHeight;<br />
DisplayButtons();}<br />
}<br />
<br />
<br />
public ContentAlignment ButtonImageAlign<br />
{<br />
get { return mButtonImageAlign;}<br />
set <br />
{<br />
mButtonImageAlign = value;<br />
DisplayButtons();}<br />
}<br />
<br />
<br />
public ContentAlignment ButtonTextAlign<br />
{<br />
get { return mButtonTextAlign;}<br />
set <br />
{<br />
mButtonTextAlign = value;<br />
DisplayButtons();}<br />
}<br />
<br />
<br />
public string ToolbarText<br />
{<br />
get { return mToolbarText;}<br />
set <br />
{<br />
mToolbarText = value;<br />
cmdToolbar.Text = mToolbarText;}<br />
}<br />
<br />
<br />
public Image ToolbarImage<br />
{<br />
get { return cmdToolbar.Image;}<br />
set { cmdToolbar.Image = value;}<br />
}<br />
<br />
<br />
public ContentAlignment ToolbarImageAlign<br />
{<br />
get { return cmdToolbar.ImageAlign;}<br />
set { cmdToolbar.ImageAlign = value;}<br />
}<br />
<br />
<br />
public ContentAlignment ToolbarTextAlign<br />
{<br />
get { return cmdToolbar.TextAlign;}<br />
set { cmdToolbar.TextAlign = value;}<br />
}<br />
<br />
<br />
public string Key<br />
{<br />
get { return mKey;}<br />
set { mKey = value;}<br />
}<br />
<br />
<br />
#endregion<br />
<br />
<br />
#region Events<br />
public event EventHandler ToolbarClick;<br />
<br />
protected void OnToolbarClick(EventArgs e)<br />
{<br />
if(ToolbarClick != null)<br />
{<br />
ToolbarClick(this, e);<br />
}<br />
}<br />
<br />
<br />
public event EventHandler ButtonClick;<br />
<br />
protected void OnButtonClick(EventArgs e)<br />
{<br />
if(ButtonClick != null)<br />
{<br />
ButtonClick(this, e);<br />
}<br />
}<br />
<br />
#endregion<br />
<br />
<br />
<br />
public tbToolbar()<br />
{<br />
InitializeComponent();<br />
DisplayButtons();<br />
<br />
}<br />
<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if( components != null )<br />
components.Dispose();<br />
}<br />
base.Dispose( disposing );<br />
}<br />
<br />
#region Component Designer generated code<br />
private void InitializeComponent()<br />
{<br />
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(tbToolbar));<br />
this.cmdToolbar = new System.Windows.Forms.Button();<br />
this.pnlPanel = new System.Windows.Forms.Panel();<br />
this.hbDefault = new HoverButton.hbHoverButton();<br />
this.pnlPanel.SuspendLayout();<br />
this.SuspendLayout();<br />
this.cmdToolbar.BackColor = System.Drawing.SystemColors.Control;<br />
this.cmdToolbar.Dock = System.Windows.Forms.DockStyle.Top;<br />
this.cmdToolbar.Location = new System.Drawing.Point(0, 0);<br />
this.cmdToolbar.Name = "cmdToolbar";<br />
this.cmdToolbar.Size = new System.Drawing.Size(119, 28);<br />
this.cmdToolbar.TabIndex = 0;<br />
this.cmdToolbar.Text = "Toolbar";<br />
this.cmdToolbar.Click += new System.EventHandler(this.cmdToolbar_Click);<br />
this.pnlPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) <br />
| System.Windows.Forms.AnchorStyles.Left) <br />
| System.Windows.Forms.AnchorStyles.Right)));<br />
this.pnlPanel.AutoScroll = true;<br />
this.pnlPanel.Controls.Add(this.hbDefault);<br />
this.pnlPanel.Location = new System.Drawing.Point(0, 29);<br />
this.pnlPanel.Name = "pnlPanel";<br />
this.pnlPanel.Size = new System.Drawing.Size(119, 344);<br />
this.pnlPanel.TabIndex = 2;<br />
this.hbDefault.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) <br />
| System.Windows.Forms.AnchorStyles.Right)));<br />
this.hbDefault.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(33)), ((System.Byte)(86)), ((System.Byte)(152)));<br />
this.hbDefault.ButtonBackColour = System.Drawing.Color.FromArgb(((System.Byte)(33)), ((System.Byte)(86)), ((System.Byte)(152)));<br />
this.hbDefault.ButtonBorderSize = 2;<br />
this.hbDefault.ButtonImage = ((System.Drawing.Image)(resources.GetObject("hbDefault.ButtonImage")));<br />
this.hbDefault.ButtonImageAlign = System.Drawing.ContentAlignment.TopCenter;<br />
this.hbDefault.ButtonText = "hoverButton";<br />
this.hbDefault.ButtonTextAlign = System.Drawing.ContentAlignment.BottomCenter;<br />
this.hbDefault.ClickedBackColour = System.Drawing.Color.FromArgb(((System.Byte)(67)), ((System.Byte)(133)), ((System.Byte)(214)));<br />
this.hbDefault.ClickedBorderColour = System.Drawing.Color.FromArgb(((System.Byte)(40)), ((System.Byte)(104)), ((System.Byte)(183)));<br />
this.hbDefault.ForeColor = System.Drawing.Color.White;<br />
this.hbDefault.HoverBackColour = System.Drawing.Color.FromArgb(((System.Byte)(40)), ((System.Byte)(104)), ((System.Byte)(183)));<br />
this.hbDefault.HoverBorderColour = System.Drawing.Color.FromArgb(((System.Byte)(67)), ((System.Byte)(133)), ((System.Byte)(214)));<br />
this.hbDefault.Location = new System.Drawing.Point(7, 2);<br />
this.hbDefault.Name = "hbDefault";<br />
this.hbDefault.Size = new System.Drawing.Size(104, 54);<br />
this.hbDefault.TabIndex = 0;<br />
this.hbDefault.Visible = false;<br />
this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(33)), ((System.Byte)(86)), ((System.Byte)(152)));<br />
this.Controls.Add(this.pnlPanel);<br />
this.Controls.Add(this.cmdToolbar);<br />
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));<br />
this.ImeMode = System.Windows.Forms.ImeMode.NoControl;<br />
this.Name = "tbToolbar";<br />
this.Size = new System.Drawing.Size(119, 372);<br />
this.Load += new System.EventHandler(this.tbToolbar_Load);<br />
this.pnlPanel.ResumeLayout(false);<br />
this.ResumeLayout(false);<br />
<br />
}<br />
#endregion<br />
<br />
<br />
public void AddButton(string strName, Image imgImage)<br />
{<br />
HoverButton.hbHoverButton tbNewButton = new HoverButton.hbHoverButton();<br />
<br />
tbNewButton.ButtonText = strName;<br />
tbNewButton.ButtonImage = imgImage;<br />
tbNewButton.Left = hbDefault.Left;<br />
tbNewButton.Width = pnlPanel.Width - 11;<br />
tbNewButton.ForeColor = Color.White;<br />
tbNewButton.Anchor = hbDefault.Anchor;<br />
tbNewButton.Visible = true;<br />
tbNewButton.Click += new EventHandler(HoverButton_Clicked);<br />
<br />
alButtons.Add(tbNewButton);<br />
<br />
DisplayButtons();<br />
}<br />
<br />
<br />
public void RemoveButton(int intIndex)<br />
{<br />
HoverButton.hbHoverButton btnTemp = (HoverButton.hbHoverButton)alButtons[intIndex];<br />
alButtons.Remove(btnTemp);<br />
<br />
DisplayButtons();<br />
}<br />
<br />
<br />
private void DisplayButtons()<br />
{<br />
<br />
pnlPanel.Controls.Clear();<br />
<br />
<br />
for(int i =0; i < alButtons.Count; i++)<br />
{ <br />
HoverButton.hbHoverButton btnTemp = (HoverButton.hbHoverButton)alButtons[i];<br />
<br />
btnTemp.Top = (mButtonHeight * (i)) + 6;<br />
btnTemp.Height = mButtonHeight;<br />
btnTemp.ButtonImageAlign = mButtonImageAlign;<br />
btnTemp.ButtonTextAlign = mButtonTextAlign;<br />
<br />
this.pnlPanel.Controls.Add(btnTemp);<br />
}<br />
}<br />
<br />
<br />
private void cmdToolbar_Click(object sender, System.EventArgs e)<br />
{<br />
OnToolbarClick(e);<br />
}<br />
<br />
<br />
private void HoverButton_Clicked(object sender, EventArgs e)<br />
{<br />
OnButtonClick(e);<br />
}<br />
<br />
<br />
private void tbToolbar_Load(object sender, System.EventArgs e)<br />
{<br />
DisplayButtons();<br />
}<br />
<br />
<br />
public HoverButton.hbHoverButton Button(int intIndex)<br />
{<br />
if((intIndex+1) > alButtons.Count)<br />
{<br />
return null;<br />
}<br />
else<br />
{<br />
HoverButton.hbHoverButton tbButton = (HoverButton.hbHoverButton)alButtons[intIndex];<br />
return tbButton;<br />
}<br />
}<br />
}<br />
<br />
<br />
public class clsHoverButtonProp<br />
{<br />
<br />
private string mButtonText = "";<br />
private System.Drawing.Image mButtonImage;<br />
<br />
<br />
public string ButtonText<br />
{<br />
get { return mButtonText;}<br />
set { mButtonText = value;}<br />
}<br />
<br />
public System.Drawing.Image ButtonImage<br />
{<br />
get{ return mButtonImage;}<br />
set{ mButtonImage = value;}<br />
}<br />
<br />
public clsHoverButtonProp()<br />
{<br />
}<br />
<br />
}<br />
}<br />
|
|
|
|
|
I am working on creating a windows service. Here I have to watch a folder for any file that is placed in that folder. If a file is placed in that folder i have to process it. I am doing this with the filesystemwatcher component's created method. This works fine when i am placing files one by one. But when i place 5 or 6 files at the same time, or when i place a file of bigger size, say above 3 MB, it produces error, saying that the an system.ioexception has occurred. The file is being used by another application. I think this is due to the fact that the windows takes some time to copy that file to that folder, whereas filesystemwatcher components starts it's execution as soon as it finds a file in that folder.
Any suggestion will be very welcome
|
|
|
|
|
Hi
Create a seperate thread in which you will process that file. For instance, if you have 5 files moved into the folder, you will be having 5 threads that would process those files. In every thread, make a variable that would be having state of the file. whenever a file is copied into the filesystem, filesystemwatcher trigers Created event once and then Changed event twice. When the Chnaged event is fired for the same file for the second time then start doing anythng on that file.
Hope it helps
Regards
Khalid
|
|
|
|
|
Hi!
Does any one know of an example for reading/presenting the outline coords of a character in a true type font, in C#?
Thanks,
Paul
|
|
|
|
|
I'm using a modem(GMS/GPRS). How to transfer data modem through internet, and I can use C# to communication with this modem? who can help me,please?
|
|
|
|
|
Hello,
I need to check the version of DLL library that I'm using in my program. How do I do that at runtime?
Thanks much for any input.
Michal Kreslik
|
|
|
|
|
hi Michal,
i don't know exactly but i hope this information is going to help u. just paste this link on ur browser and c: www.codeproject.com/system/library_version.asp
Regards,
Rahithi
|
|
|
|
|
Thanks, Rahithi,
but the article at your link deals with C++ code. Do you know about any C# example?
Thanks,
Michal
|
|
|
|
|
Michal,
sorry for sending the wrong article.
as per my knowledge(i am new to .Net) If it's a managed assembly you're loading, you can check
System.Reflection.Assembly.GetName().Version.
and For native DLLs you can use the FileVersionInfo class.
hope this will help
regards,
Rahithi
|
|
|
|
|
Rahithi,
thanks. It's a COM library I'm referencing, so I can't use the System.Reflection namespace directly I guess. But maybe I could use the System.Reflection namespace to get the external DLL's version by using a non-static method System.Reflection.Assembly.GetModule().ModuleVersionId. But I have yet to find out how to do that.
Unfortunately, getting the fileversion information thru FileVersionInfo.GetVersionInfo() doesn't work neither since it keeps returning "1.0.0.0" for a DLL that has a Runtime version of "v2.0.50727".
What am I trying to accomplish here is to get the information that's visible in the Properties tab under "Runtime Version" if you click on the appropriate library in the References solution folder.
Any idea?
Thanks,
Michal Kreslik
|
|
|
|
|
I'm using a monospace font and trying to use e.Graphics.MeasureString("0", viewerFont); except the width that returns isn't the right width. I've tried using the two MeasureDisplayStringWidth functions in an article on here, but these also produce the wrong values. The bitmap drawing one is the closest so far. I just need to know how many pixels a single character is, I don't see why that should be so hard to do
|
|
|
|
|
Actually we want to crop certain area from the image,so for this porpose we try this code...but now the problem is that although we got the reactangle
the code is as follow!!
Graphics g=this.CreateGraphics();
RectangleF Destinationrectangle=new RectangleF(530,30,100,190);
RectangleF Sourcerectangle=new RectangleF(topleft,topright,bottomleft,bottomright);
g.DrawImage(this.BinaryImage.Image,Destinationrectangle,Sourcerectangle,GraphicsUnit.Pixel);
Now We Want to convert Destinationrectangle into Bitmap,(Is this Possible),and plz guide us how to insert this bitmap in to pictureBox
Plz Reply SOON
|
|
|
|
|
Why don't you draw on a bitmap?
Bitmap bmp = new Bitmap(...);
Graphics g = Graphics.FromImage(bmp)
//... do the drawing
g.Dispose();
____________________________________
There is no proof for this sentence.
|
|
|
|
|
hi
try this
private Bitmap CreateNewBitmap(int width, int height)
{
Bitmap myBitmap = null;
// create a new bitmap with width and height of your chooise
using(Bitmap bmpNew = new Bitmap(width, height))
{
using(Graphics g = Graphics.FromImage(bmpNew))
{
RectangleF Destinationrectangle=new RectangleF(0,0,bmpNew.Width,bmpNew.Height);
RectangleF Sourcerectangle=new RectangleF(topleft,topright,bottomleft,bottomright);
g.DrawImage(this.BinaryImage.Image,Destinationrectangle,Sourcerectangle,GraphicsUnit.Pixel);
}
// Now create the new Bitmap
myBitmap = new Bitmap(bmpNew);
}
return myBitmap;
}
|
|
|
|
|
thanx for responding !!
but now how will i eqiulate this bitmap into pictureBox
|
|
|
|
|
//call the function and set the bitmap the the picture box
myPictureBox.Image = CreateNewBitmap(100, 100);
|
|
|
|
|
IS there is aNY Simple way through which we can convert RectangleF to Bitmap?
|
|
|
|
|
Hi, I want to have same corner handles for the buttons (and other controls,
too)
as at design in VisualStudio. How can I programm that with C#?
Thanks.
|
|
|
|
|
hello all.
i'm trying to create relationship among tables in a database. can anyone tell me how to create a one to one/ one to many/ many to many relationship between two tables. i'm trying to create them at runtime not statically.
please reply soon.
ur help will be greatly appreciated.
thanks
|
|
|
|
|
hi there,
I'm not sure what you're trying to do here. Do you actually need the relationships created between the tables or are you just trying to query data using joins. I believe that each DB engine will have a slightly different way of creating things like relationships.
this is the code for sql2000
ALTER TABLE Person
ADD CONSTRAINT Person_AddressID
FOREIGN KEY (AddressID)
REFERENCES Address(AddressID)
HTH
Russ
|
|
|
|
|
thanks buddy for the idea.
however i'm encountering another problem.
i'm using the following sql query to display all information of a table.
string table_name1=comboBox1.Text;<br />
string sql_query="DESCRIBE "+table_name1;<br />
<br />
try<br />
{<br />
cmd=new SqlCommand(sql_query,conn);<br />
cmd.ExecuteNonQuery();<br />
}<br />
catch(SqlException ae)<br />
{<br />
MessageBox.Show(ae.Message.ToString());<br />
}
the error i'm gettin is
could not find stored procedure 'DESCRIBE'
could u please guide me about this.
is there any error with the query??
i tried using the keyword DESC also but it still gives an error.
plz help
thanks
|
|
|
|
|
Sql Server doesn't have any defination for Desc or Describe .use following query to get column information of a table
SELECT Column_Name, Data_TYPE FROM Information_Schema.Columns WHERE (TABLE_NAME = 'TableName')
sameer
|
|
|
|
|