Results 1 to 10 of 10

Thread: [RESOLVED] MessageBox layout

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    487

    Resolved [RESOLVED] MessageBox layout

    The layouts of the MessageBox dialogs in my application are not right. The text overlaps the icon. Here's an example:

    Name:  Image #1.png
Views: 373
Size:  19.6 KB

    The code that creates this dialog is pretty simple:

    Code:
    strMSG = "No SyncBackPro operation is necessary today."
    MessageBox.Show(strMSG, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information)
    I'm stumped as to why the layout is not right and would appreciate any suggestions to correct this.

  2. #2
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Re: MessageBox layout

    There must be something else going on...using that exact code works OK for me:
    Attached Images Attached Images  
    Please remember next time...elections matter!

  3. #3
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,392

    Re: MessageBox layout

    Are you using Windows 10?

    Is display scaling set to something other than 100%?

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    487

    Re: MessageBox layout

    Yes, it a Windows 10, version 1809 machine. I’ve done a lot of VB.Net work and this is the first time I’ve seen this.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    487

    Re: MessageBox layout

    Yes, it a Windows 10, version 1809 machine. I’ve done a lot of VB.Net work and this is the first time I’ve seen this.

  6. #6
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: MessageBox layout

    Quote Originally Posted by jdc2000 View Post
    Are you using Windows 10?

    Is display scaling set to something other than 100%?
    Yes that is what I would suspect. If not other things I don't remember seeing it that bad?

    Check your text scaling setting in control panel ie 200 percent?

    Perhaps try setting dpi aware in app.manifest as discussed in this thread. Make backups etc first.

    PS Here are the dpi aware threads to look at:

    Have you tried adding DPI AWARE options to your application using various app manifest.

    There are many details its tricky.
    Last edited by tommytwotrain; Jan 23rd, 2019 at 09:28 PM.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    487

    Re: MessageBox layout

    Looking through my project for some clues as to what might be happening. This project is a Windows Forms Application. It does not have any forms (including a startup form), it uses the Main sub-routine in the modMain module as the startup object. To do this, I had to un-check the “Use Entity Framework” checkbox for the Project.

    If I add a form to the project, check the “Use Entity Framework” checkbox for the Project, and set the form to be the startup object, then the MessageBox layout is correct (no overlap of the icon and the text). Just like the one in Tyson’s reply (see post #2 above).

    If i create a new Console Application, set a reference to System.Windows.Forms, import the modMain from my original application, and make modMain the startup object, then the MessageBox layouts have the problem as shown in my initial post above.

    Why does the MessageBox appear differently in a Console Application vs. a Windows Forms Application?
    Last edited by Mark@SF; Jan 23rd, 2019 at 11:13 PM.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: MessageBox layout

    There is no Application Framework (not Entity Framework) in C# so, when you create a WinForms app project in C#, it generates a Main method for you and it looks like this:
    csharp Code:
    1. /// <summary>
    2. /// The main entry point for the application.
    3. /// </summary>
    4. [STAThread]
    5. static void Main()
    6. {
    7.     Application.EnableVisualStyles();
    8.     Application.SetCompatibleTextRenderingDefault(false);
    9.     Application.Run(new Form1());
    10. }
    You need to make those two initial method calls in your own Main method in VB if you use one. Presumably you are not calling Application.SetCompatibleTextRenderingDefault and that's causing this issue.

    By the way, if you're not using a startup form then are you still calling Application.Run and passing a custom ApplicationContext? If not, you should be. To learn how, check out the thread below.:

    http://www.vbforums.com/showthread.php?636812

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    487

    Re: MessageBox layout

    JMC -

    Thanks for the follow-up. My bad re: the framework (I was working off-line on my iPad last night and relying on my memory instead of the actual VB Studio screen!). It is indeed the "Enable application framework" checkbox.

    Your suggestion to set the Application's EnableVisualStyles property solved my MessageBox layout issue. The SetCompatibleTextRenderingDefault property didn’t make any difference wrt the MessageBox problem (My Googling on it indicates this property is for back-capability with Net 1.x which doesn’t really apply to my situation). Since I don't have any forms in my project, I didn't include the "Application.Run(new Form1())" statement that you suggested.

    Thanks again for your help. Every time I come to this forum with a question I always am amazed at the willingness of the members to help and its much appreciated! There's a lot I need to learn and this is a great place for that.
    Last edited by Mark@SF; Jan 24th, 2019 at 02:25 PM.

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: MessageBox layout

    Quote Originally Posted by Mark@SF View Post
    Since I don't have any forms in my project, I didn't include the "Application.Run(new Form1())" statement that you suggested.
    Not having any forms is not a reason not to call Application.Run. As I said, you should still be making that call and passing an ApplicationContext instead of a form. The link I provided demonstrates how to do that.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width