Quantcast
Channel: Windows Forms General forum
Viewing all 12583 articles
Browse latest View live

Control to Bitmap without DrawToBitmap

$
0
0

Hi,


I am trying to paint a Control to a Bitmap. I don't want to use DrawToBitmap, because it has a few Bugs (Z-Order, disappearing Elements, ...)

I am trying to using Reflection and OnPaint. That's the Method:

        Bitmap ControlToBitmap(Control control)
        {
            Bitmap bitmap = new Bitmap(control.Width, control.Height);
            Graphics g2 = Graphics.FromImage(bitmap);
            Rectangle clipRect = new Rectangle(0,0,control.Width, control.Height);
            g2.Clip = new System.Drawing.Region(clipRect);
            PaintEventArgs pea = new PaintEventArgs(g2, clipRect);
            Type type = control.GetType();
            BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance;
            MethodInfo method = type.GetMethod("OnPaint", flags);
            method.Invoke(control, new object[] { pea });
            return bitmap;
        }

I have two Problems. The first:

The button on the top is the result of my funktion, but should look like the bottom-button.

The second problem is, that this does not work for all Controls, for ProgressBar for example it does not work.

Does someone know why my funktion works not correct, or maybe a third way to paint a Control to a Bitmap?

Thanks

Ludwig


csc.exe error on building windows forms app in vs 2015 community

$
0
0

Hi, i have.. "csc.exe" exited with code-1073741818.. error in my vs 2015 community edition..does anyone knows how to solve it?

How to isolate and modify a rectangle

$
0
0

I am building a graph using the following code.  I need to be able to change the color of any given rectangle by clicking on it with the mouse.  I am, so far, unable to find a way to accomplish this.

Any ideas would be greatly appreciated.       

        int number;
        public List<Rectangle> listRec = new List<Rectangle>();
        Graphics g;        public CrochetPtrnDesign()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {            try            {            number = int.Parse(textBox1.Text);                Rectangle rect = new Rectangle();                listRec.Clear();                rect.Size = new Size((pnlDesign.Width - 1) / number, (pnlDesign.Height - 1) / number);                for (int x = 0; x < number; x++)                {                    rect.X = x * rect.Width;                    for (int y = 0; y < number; y++)                    {                        rect.Y = y * rect.Height;                        listRec.Add(rect);                    }                }            }            catch            {                MessageBox.Show("Please enter a number...");            }            foreach (Rectangle rec in listRec)            {                g = pnlDesign.CreateGraphics();                Pen p = new Pen(Color.Black);                g.DrawRectangle(p, rec);            }        }

Background Worker "Cross-thread operation not valid; Control *controlhere* accessed from thread other than the thread it was created"

$
0
0

I have a combobox with a list of crewmembers on a forum. The user selects a crewmember, an SQL query fires and obtains the credentials for the corresponding crewmember, and displays them in a textbox. This process can take a few second. I'm using the backgroundWorker to keep the UI from locking up while this takes place. Below is the code:

//Combobox Selection Event
private void cboTertiary_SelectionIndexChanged(object   sender, EventArgs e)
        {
            string crewMember = cboTertiary.Text;
            backgroundWorker1.RunWorkerAsync(crewMember);
        }

//Background Worker DoWork Event

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            {
                try
                {


                    string crewMember = (string)e.Argument.ToString();

                    OleDbConnection connection = new OleDbConnection();
                    connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source = S:\Databases\TestApplications\backend\FollowUpApp_BE.accdb;
                                                Persist Security Info=False";

                    connection.Open();

                    OleDbCommand getCredentials = new OleDbCommand();
                    getCredentials.Connection = connection;
                    string query = "select Credentials FROM tblCrewmembers WHERE Crewmember='" + cboTertiary.Text + "'";
                    getCredentials.CommandText = query;

                    OleDbDataReader reader = getCredentials.ExecuteReader();

                    while (reader.Read())
                    {

                        string credential = reader["Credentials"].ToString();

                        e.Result = credential.ToString();

                    }

                    reader.Close();
                    connection.Close();
                }
                catch (System.Reflection.TargetInvocationException ex)
                {
                    MessageBox.Show("Error: " + ex);
                }
            }
        }

//Backgroundworker RunWorkerCompleted Event

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {

                //******ERROR OCCURS HERE******
                txtTertiaryCred.Text = e.Result.ToString();
            }
            catch (System.Reflection.TargetInvocationException ex)
            {
                MessageBox.Show("Error: " + ex);
            }
        }
I've searched for a solution for hours and haven't found one.


Auto replace image in picturebox

$
0
0
Hi,

I just want to ask how to auto replace an image in a picture box. Let say, I capture image1, then picturebox1 will load image1. Then, capture image2, then image2 will replace image1 in the same picture box without using any button to click.

Thanks

Auto replace image in picturebox using vb.net

$
0
0
Hi,

I just want to ask how to auto replace an image in a picture box. Let say, I capture image1, then picturebox1 will load image1. Then, capture image2, then image2 will replace image1 in the same picture box without using any button to click.

Thanks


SaveFileDialog crash with exception code 0xc0000005

$
0
0

I have an issue with application in C#. When I try to call ShowDialog on SaveFileDialog object application crashes.
The code which causes crash is in try catch block, but since it crahses application I'm unable to get stack trace.

 try
            {
                SaveFileDialog sfd = new SaveFileDialog();

                sfd.AddExtension = true;
                sfd.RestoreDirectory = true;
                string ext = Path.GetExtension(this.title);
                sfd.Filter = "File type (" + ext + ")|*" + ext;
                sfd.FileName = Program.NormalizeTitle(this.title);

                DialogResult ds = sfd.ShowDialog(this);

                if (ds != DialogResult.Cancel)

            }
            catch (Exception ex)
            {
                 MessageBox.Show("Exception: " + ex.StackTrace);
            }

This is the error description:

Faulting application name: test.exe, version: 1.0.0.1, time stamp: 0x56585459
Faulting module name: wkscli.dll, version: 6.1.7601.17514, time stamp: 0x4ce795a7
Exception code: 0xc0000005
Fault offset: 0x00001e8f
Faulting process id: 0x%9
Faulting application start time: 0x%10
Faulting application path: %11
Faulting module path: %12

Sometimes faulting module name is Ntshrui.dll.

This code works fine for years on any other machine. It happend on Windows 2008 R2 with .Net 2.0 and 4.0.
What could be the problem?

Control Panel GPO

$
0
0
I am trying to restrict what Control Panel items my users are able to see and access. I have enabled the Show only the specified Control Panel items. I have added the Canonical names for the Keyboard, Mouse, Device and Printers, File Explorer Options, and Display. All the Control Panel items show up with the exception of the Display icon. I am entering Microsoft.Display as the canonical name. I am running Windows 2012 R2 server. The desktop is running Windows 10.  

Android development issue with Xamarin

$
0
0

Hello,

I would like to ask if there is anyone with a working development setup of Xamarin for Android development. I can't figure out what is going on. If there is anyone working with Xamarin.Forms for Android? Please record a video showing how to set it up.

Control PAnel GPO

$
0
0
I am trying to restrict what Control Panel items my users are able to see and access. I have enabled the Show only the specified Control Panel items. I have added the Canonical names for the Keyboard, Mouse, Device and Printers, File Explorer Options, and Display. All the Control Panel items show up with the exception of the Display icon. I am entering Microsoft.Display as the canonical name. I am running Windows 2012 R2 server. The desktop is running Windows 10.  

Vertical scrollbar behavior with touch screen

$
0
0

When I swipe up, vertical scrollbar moves down and swiping down makes the scrollbar moves up. Is there any way to stop this behavior of vertical scrollbar ?

I have explained the question in more detail in the following link

http://stackoverflow.com/questions/39092215

From my analysis, I found the following things

1) Swiping up or down on a control, searches for a vertical scrollbar in child controls

2) If vertical scrollbar is found, some flag (say changeVerticalBehavior) is set to true.

3) Once this flag is enabled, it is not disabling. So vertical scrollbar always move in the opposite direction

My question is,

1) How to stop the control from searching for a vertical scrollbar ?

2) What is the flag set on vertical scrollbar that affects the scrolling behavior ? Is it possible to reset it ?

Note: I mentioned flag here, because I don't have the source code for vertical scrollbar class.

C#4.0:To copy colored richTextBox to text of comboBox

$
0
0

Hello

I wrote this code but colored text in richTextBox will not be copied to the text of comboBox.

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.Text = "Hello. How are you?";
            richTextBox1.Text = comboBox1.Text;
            richTextBox1.Select(richTextBox1.Text.IndexOf("How"), "How".Length);
            richTextBox1.SelectionColor = Color.Green;
        }


Help

$
0
0

hi, i want to hide my winform application to task manager and i does not want form.text="".

so please help me to solve this problem?

Window Web browser control unable to execute javascript with office add-ins task pane app.

$
0
0

We are using chatter component (Salesforce standard control) to display feeds. All feeds are rendered on our application using window web browser control. Some of the functionality in chatter component feeds such like attach file link , @Mention in comment section doesn't work in web browser control.

When I access the page with the Internet browser 10 or 11, the browser is rendering ok and everything working fine.

How can I solve this problem ?

Thanks in advance.

Hardik Shah


Thanks, Hardik Shah



Need to install Sanskrit font

$
0
0
Need to install Sanskrit font on my MS word

C#: Shift Key+ left (right) arrow key and selection of all text in richTextBox

$
0
0

Hello

I wrote this code. I can change the language but with shift+left arrow key (or right arrow key) I cannot select all of the text in the richTextBox.

        private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (InputLanguage.CurrentInputLanguage.Culture.Name == "fa-IR")
            {
                richTextBox1.Select(richTextBox1.SelectionStart, 0);
                richTextBox1.SelectionFont = new Font("Tahoma", 12, FontStyle.Bold);
            }
            else if (InputLanguage.CurrentInputLanguage.Culture.Name == "en-US")
            {
                richTextBox1.Select(richTextBox1.SelectionStart, 0);
                richTextBox1.SelectionFont = new Font("Tahoma", 10, FontStyle.Regular);
            }
        }


List.Sort incompatibility with Visual Studio 2015 (.NET 4.6.1)

$
0
0

Hi,

My application was worked fine with VS2010 IDE compiled with .NET 4.0.

When I installed VS2015 and compiled my application with .NET 4.6.1, I got below error,

an IComparer<> we were using in calls to List<>.Sort now causes an ArgumentException:

Unable to sort because the IComparer.Compare() method returns inconsistent results. Either a value does not compare equal to itself, or one value repeatedly compared to another value yields different results.

Kindly provide the solution for above exception.

Thanks,

Bharathraj

Why Does My ComboBox SelectedIndexChanged Function Get Hit When The Form Loads?

$
0
0

Hi,

I double clicked on the combobox to get the method created automatically in the form. NB. this form opens up on a button click. The problem is this function now gets hit everytime the form is loaded, why is this and how do I work around this?

How can I convert HTML in the clipboard to RTF in c# for insertion into a RichTextBox?

$
0
0

There is already an answer answer proposed here:

http://stackoverflow.com/questions/439301/convert-rtf-to-html

But it didn't work for me because it depends on WPF, which is no longer supported: I reported this in a previous thread I started (and abandoned) - namely that: 

using System.Windows.Documents

produces a compiler error in Visual Studio Community 2015 and the solution above requires the above using statement. I assume the failure of the using statement is because System.Windows.Documents is no longer available. 

So how can I convert HTML to RTF as in the Title box?

I know that I can convert HTML to RTF via this:

	  public void renderClipboardHtml(textBox1 inTextBox)
	  {
		string myString;

		var webBrowser = new WebBrowser();
		myString = (string)Clipboard.GetData(DataFormats.Html);
		webBrowser.CreateControl(); // only if needed
		webBrowser.DocumentText = myString;
		while (webBrowser.DocumentText != myString)
		    Application.DoEvents();

		webBrowser.Document.ExecCommand("SelectAll", false, null);
		webBrowser.Document.ExecCommand("Copy", false, null);
		inTextBox.Paste();
	  }

but it produces this result with a few lines copy/pasted from Wikipedia (NOTE: I am not trying to violate any Wikipedia copyright or intellectual property rights - this is for private use):

Version:0.9 StartHTML:0000000185 EndHTML:0000003329 StartFragment:0000000221 EndFragment:0000003293 SourceURL:https://en.wikipedia.org/wiki/Indonesian_killings_of_1965%E2%80%9366 
Current events <https://en.wikipedia.org/wiki/Portal:Current_events> 
Random article <https://en.wikipedia.org/wiki/Special:Random> 
Donate to Wikipedia <https://donate.wikimedia.org/wiki/Special:FundraiserRedirector?utm_source=donate&utm_medium=sidebar&utm_campaign=C13_en.wikipedia.org&uselang=en> 
Wikipedia store <https://shop.wikimedia.org/>

What I want is a copy of the Wikipedia lines as they appear on Wikipedia, which is this:

Current events 
Random article
Donate to Wikipedia 
Wikipedia store

where each line is in blue and underlined, and if clicked will go to the url specified in the html above.


Splitcontainer not displaying properly on Surface Pro 4

$
0
0

Ok, I have messed around with all the Autoresize settings I can find but something strange is happening on my Surface Pro that sis not happen on my laptop.

I have 2 split containers nested inside each other to give me basically a header and Y-axis label with a datagridview.

In the designer, everything looks good, but when I run it, it doubles or triples the splitterdistance giving me tons of whitespace...

But when I run the program, it displays like this...

I have tried setting the splitterdistance as the last line in the Load and Shown Events..

SplitContainer2.SplitterDistance = 60
SplitContainer1.SplitterDistance = 115

I can resize them manually when running to the correct size.... I've been trying to figure this out on and off for a couple weeks.

Any help is appreciated,

John


Man, Im in way over my head!!!

Viewing all 12583 articles
Browse latest View live