2

When working on an application i decide to add my first user control for that project. I make it just fine, however when i drag it in to my main form from the toolbox it pops up with an error message:

enter image description here

No matter what i do it doesn't seem to fix it. I have tried adding it through code however it simply wouldn't show up at all.

Looking in to the problem online I was not able to find a working solution, or at least no solution that I could follow and understand.

Help would really be appreciated, and if any more information is needed I would be glad to add it. However currently I don't know what I could add that could be of any use.

The code is for a simple prank virus (Have to inspire myself to keep learning to code :) ) Here is the code (Please don't launch the file, it is a prank virus after all, the only way to exit is alt+f4):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Simple_virus_V2
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        internal static extern IntPtr SetForegroundWindow(IntPtr hWnd);

        [DllImport("user32.dll")]
        internal static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        public Form1()
        {
            InitializeComponent();
            timer1.Start();
            timer2.Start();

            
            Thread newthread = new Thread(progress);
            newthread.Start();
        }
        Random rnd = new Random();
        int noticewidth = 0;
        bool changecursor = false;
        
        private void progress() {

            Thread.Sleep(1000);
            changecursor = true;
            Thread.Sleep(1000);
            timer3.Start();
            Thread.Sleep(5000);
            noticewidth = Width;

        }
        int mouseflash = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (changecursor) {

                if (mouseflash < 1000)
                {
                    Bitmap cursor = new Bitmap(new Bitmap(pictureBox1.Image), 24, 24);
                    Cursor = new Cursor(cursor.GetHicon());
                
                
                } else if (mouseflash < 1700) {

                    Bitmap cursor = new Bitmap(new Bitmap(pictureBox2.Image), 30, 30);
                    Cursor = new Cursor(cursor.GetHicon());

                }
                else {

                    mouseflash = 0;
                }


                mouseflash = mouseflash + rnd.Next(3,10);
            }
            header.Left = MousePosition.X - (header.Width / 2);
            label2.Left = MousePosition.X - (label2.Width / 2);
            label3.Left = label2.Left + 25;

            panel1.Width = noticewidth;
            this.Location = new Point(0,0);
            panel1.Location = new Point(0, MousePosition.Y - 40);
            this.WindowState = FormWindowState.Maximized;
            TopMost = true;
            
            Process currentProcess = Process.GetCurrentProcess();
            IntPtr hWnd = currentProcess.MainWindowHandle;
            if (hWnd != IntPtr.Zero)
            {
                SetForegroundWindow(hWnd);
                ShowWindow(hWnd, int.Parse("9"));
            }
            
            Focus();
            this.Width = Screen.PrimaryScreen.Bounds.Width * 3;
            this.Height = Screen.PrimaryScreen.Bounds.Height * 2; 
            
        }

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {

            
            
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            /*
            using (Form1 frm = new Form1()) {
                if (frm.ShowDialog() == DialogResult.OK) {

                }
            }
            */
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            
            
            PictureBox pic = new PictureBox();
            pic.Width = 1;
            pic.Height = 1;
            pic.BackColor = Color.Black;
            pic.Location = new Point(rnd.Next(0, this.Width), rnd.Next(0, this.Height));
            this.Controls.Add(pic);
            

        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            /*
            bartry bars = new bartry();
            bars.Location = new Point(0, rnd.Next(0, 500));
            Controls.Add(bars);


            timer3.Interval = rnd.Next(100, 5000);
            */
        }
    }
}

Thanks

Community
  • 1
  • 1
Simkoo
  • 74
  • 1
  • 10
  • have you looked at this [Failed to load toolbox item. It will be removed from the toolbox](https://stackoverflow.com/questions/27289366/failed-to-load-toolbox-item-it-will-be-removed-from-the-toolbox) my guess is this will end up a duplicate of one of the answers – TheGeneral Sep 06 '18 at 08:55
  • I did read that, but i couldn't find out what the answer meant, since i am reasonably new to winforms. Could somebody please elaborate that top answer. if not i'll probably remove this question because it is kind of a duplicate, i just didn't want to ask a question on an already answered question – Simkoo Sep 06 '18 at 08:58
  • Actually its the top voted answers that are more likely to help – TheGeneral Sep 06 '18 at 09:00
  • Also its goign to be near impossible to answer this question without code – TheGeneral Sep 06 '18 at 09:00
  • I would be happy to provide the code, and i did try the answere with 16 upvotes multiple times, it didn't work – Simkoo Sep 06 '18 at 09:02
  • I added the code, if this helps – Simkoo Sep 06 '18 at 09:07

2 Answers2

1

After ages of trying out the answers on the other post none of them ended up working. I did find the solution after opening a new project and experimenting around with my code.

The solution: Make sure that the user control and the main forms have the same "using" references!

Sorry if this was self explanatory, but i didn't know that you had to do that.

Simkoo
  • 74
  • 1
  • 10
-2

Just debug the project then try to add the User control form