[Solved] Getting folder icon path

here is the function that i wanted: string getIconPath(string folderPath) { SHFILEINFO shinfo = new SHFILEINFO(); Win32.SHGetFileInfo(folderPath, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), (int)0x1000); return shinfo.szDisplayName } and here are the SHFILEINFO struct and Win32 class implementations: [StructLayout(LayoutKind.Sequential)] public struct SHFILEINFO { public IntPtr hIcon; public int iIcon; public uint dwAttributes; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string … Read more

[Solved] How to pass an image from form to another form [closed]

Storing the image in an Image type variable and passing the variable by the constructor of your second form. Something like this : Image myImage = Image.FromFile(“C:\\… Pathtotheimage… “); MyForm form = new MyForm(myImage); On the constructor side of your second form. Do something like this : Public MyForm (Image image) { //do something here … Read more

[Solved] invoked function is not working in winforms [closed]

EDITED You must pass the instance of FrmA into the constructor of FrmMenu. In FrmA: private void Print() { FrmMenu ObjMain = new FrmMenu(this); ObjMain.Show(); } In FrmMenu: public FrmMenu(FrmA f2) { f2.CreateButtons(“NEW”); } 0 solved invoked function is not working in winforms [closed]

[Solved] Making and drawing an image C#? [closed]

You could use GDI+ (and more specifically the Graphics class): // Load an existing image into a Graphics object using (var image = Image.FromFile(@”c:\work\input.png”)) using (var gfx = Graphics.FromImage(image)) { // Draw a line on this image from (0x0) to (50×50) gfx.DrawLine(new Pen(Color.Red), 0, 0, 50, 50); // save the resulting Graphics object to a … Read more

[Solved] how can i fix System.IndexOutOfRangeException: ‘Index was outside the bounds of the array.’ in my undo and redo? [closed]

One simple solution would be to use a List instead of an array. List<string> temp = new List<string>(); It will need some tweaks but it will not limit you to 100 actions. In any other case, you should decide the strategy. Do you want to delete the initial items? Then remove your first X items … Read more

[Solved] The *Design.cs file will reset automatically and delete the manually writed codes?

There are 2 Files for you Form: MyFormClass.cs here you can edit as you like, add Properties, change them, etc. MyFormClass.designer.cs // auto generated, dont put stuff here Put your custom code in the constructor after the InitializeComponent() call public MyFormClass() { InitializeComponent(); // do it here this.lblName.Top = 10; this.lblFamily.Top = this.lblName.Top + this.lblName.Height … Read more

[Solved] How can i disable moving between Tab Control tabs by mouse in c# [closed]

This doesn’t really make a lot of sense. Short of disabling the mouse cursor entirely, I don’t know how you would possibly achieve this. Even if there were a way of “ignoring” mouse clicks on the tab control tabs, that would be incredibly bad UI. As far as the user would be concerned, your application … Read more

[Solved] Check if there were any errors during validation [closed]

If you’re using an error provider and handling onvalidating, it should look like this: private void textBox1_Validating(object sender, CancelEventArgs e) { TextBox tb = sender as TextBox; if (tb.Text.Length > 0) { e.Cancel = true; errorProvider1.SetError(tb, “Please leave this textbox blank!”); } else { errorProvider1.SetError(tb, “”); } } This will prevent you clicking off the … Read more

[Solved] How to make an auto increment number based on a year

I have figured it out myself and thank you for the down votes public class SerialNumber { private static readonly MyDbContext DbContext = new MyDbContext(); public static string SrNo() { var sn = DbContext.PrimaryForms.ToList().Last().FormDescription; var array = sn.Split(“https://stackoverflow.com/”); if (int.Parse(array[0]) == DateTime.Today.Year) { return array[0] + “https://stackoverflow.com/” + (int.Parse(array[1]) + 1); } return (int.Parse(array[0]) + … Read more

[Solved] I am making a visual C# winform application. I want to store data in it [closed]

To create files, you will be using the System.IO.File namespace. This gives you access to methods such as Create(), CreateText(), WriteAllBytes(). Which method you use will depend on what type of data you are using. To save the file in your application directory, you can get the path using AppDomain.BaseDirectory So for example if you’re … Read more