Setting Word CustomTaskPane Width Dynamically - c#

I have a VSTO custom task pane. In my code, I am setting the width to be 306 and it all appears correctly in Word 2010. Howevere, in Word 2013, some of the righhand side of the pane is not visble unless I manually drag to make it wider. Note this is the same PC so resolution shouldn't be an factor. I feel that if I just increase the width in code, i am not really addressing the real issue so want a way to set the width dynamically. Note the control is being docked against the right hand side
myPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;
so see no reason part of it should be hanging of the side of the screen. Besides, even if I dock it to the left, its still missing the righthand side of the pane.
Im not sure why I should even need to set a width in code, I thought it should pick up the size set in the USerControl designer, but if I don't set the size in code, the width is even smaller. I have played around with the autosize stuff, but got nowhere. I feel I am missing something obvious. Can anyone advise please?
Also as a side question, the custom control title height is much larger in Word 2013 than Word 2010. I can't see anywhere to change this.

The reason might be because AFAIK the default resolution for Office 2013 for on screen view is 16:9 whereas the same for Office 2010 is 4:3.
I had encountered a similar situation (although for PowerPoint) where in the default resolution changes depending on whether it is Office 2010 or 2013.
So basically if you hard code the size of the task pane for 2010, I guess you will face what you are facing now(I faced it too!).
You might think of dynamically setting the width, but for that you would need to do two things
Check the Office version.This can be easily done as follows:
Microsoft.Office.Interop.Word.Application appVersion = new Microsoft.Office.Interop.Word.Application();
Change the width dynamically in TaskPane.Designer.cs class in the InitializeComponent() method.
But the problem is that you can not add your custom code in the InitializeComponent() method, else that object will not be disposed properly even after uninstalling your add-in.
And an extra instance of the Word Process will appear in Task Manager.
So, I would suggest that you set the width as per what looks acceptable in Office 2013 and I hope that you won't need to drag the task-pane in Office 2010.
As far as your second question is concerned, I think that is the default behavior.
Cheers.

Related

Easy way to do DPI scaling?

So I've been coding a program for a little over a month now, and I've encountered a problem that I have no idea how to tackle. For a while now, I've always been confused when I opened up my program on other computer, and my window size was different. I chalked it up to a different resolution, and figured the problem would be easy to solve later. Then I imported a custom font to my program, and was confused when I noticed the letters where not clear and where blurry. I figured that this was something caused by my specified font size that I was using, and left it as is. Today however, as I was doing some testing I was annoyed by the blurry text enough to go and search online for the problem and solution, only to find out my problem lay within my DPI settings (125% on the computer I had mostly programmed on.)
I have no idea what I can do about this. I started programming a little while ago, and it was hard enough figuring out how to get the custom text working, but I just have no idea where to take this.
I've been coding this program in Visual Studio C# 2010 since it's the only version I've got that won't expire, so I can't use anything that might be in the 2011 or 2012 version.
All I want is for objects to be on the same place on one computer as another with a different DPI. Is there a very simple step-by-step tutorial somewhere that I can read or watch to figure this out?
This code snipshet worked perfectly for me.
http://urenjoy.blogspot.it/2008/11/make-resolution-independent-windows-app.html
(Using Visual Studio Express 2013)
It is required that windows app should have same layout at different resolutions means there should be no effect on layout of app on changing resolution. Here are the steps to do this.
Use table layout panel
Drag control in cell of tablelayoutpanel and set anchor and dock property.
Set rowspan and colspan properties of dragged control to merge cells
Set margin and padding of dragged control with respect to cell.
drag all controls and follow same steps, complete design using tablelayoutpanel
Now set all columns and rows size of tablelayoutpanel = autosize (or in %)
Set tablelayoutpanel properties autosize = true,autosizemode = grow and shrink
Set Forms properties autosize = true,autosizemode = grow and shrink
Run windows app If your windows app opens in maximum state then set tablelayoutpanel dock property =fill.

Visual Studio display glitching out

I'm having a persistent problem with my VS2010. After working for a while, the display will start to glitch out. The code all shows as black-on-black (I use a dark background because it's easier on the eyes, but even when I switched to the default, it just makes the text white-on-white instead.) All tooltip hovers appear in the upper-left corner of the screen instead of where they're supposed to. If you select text, the code that gets selected is nowhere near where you clicked the mouse. (Not that you can read the text anyhow since it's the same color as the background.) And none of the dockable panels will appear or if they do they're all glitched out as well. The only solution seems to be closing the program and restarting it. I've been using this copy of VS2010 for years without issue, and my other projects don't seem to have any problems. This one is C#, uses a lot of Windows Forms (not WPF), has some customized Controls, but otherwise isn't all that unusual. I have the following extensions:
CodeMaid
CSharpIntellisensePresenter
InheritanceMargin
ProductivityPowerTools
Tunnel Vision Labs Output Window Services
WatermarkTextBox Control
Some of these are recently installed so they may be the culprits. Has anyone had any display problems with any of these extensions? I can live without most of them, but I'm not sure if it'll make a difference. There's no easy way to test it either, as the glitch only shows up every couple of hours or so.

In Visual C# 2010 Express, how do I add dots to the forms and see how big labels are?

I'm trying to learn how to make databases, using C# as the "master language". I've installed Microsoft Visual C# 2010 Express, created an application, etc. There's a bit of a problem though. The form on the GUI developer doesn't look normal. Usually on these things you'll see dots evenly-spaced all across the form. Also when you drag, let's say, labels on to the thing, it's pretty easy to gather exactly how big they are in both dimensions in most other IDEs. Lastly between the dots and the ease of visibility - and control - of the sizing of labels, you can usally line labels, textboxes, and other stuff up pretty easily.
In this IDE that's not quite the case. They've taken away the "coordinate dots", they've made the positioning of everything much more precise, you can't clearly see how big a label is after you put it down, etc. My question is this: How, if possible, could I switch the thing to the more traditional style in those regards?
I know my wording on this may be hard to follow. I don't know the exact terminology of some of this stuff.
Thanks!
In Visual Studio 2010 Professional, you can switch to grid mode instead of lines mode from the Options dialog box, by selecting Windows Forms Designer then setting the LayoutMode option to SnapToGrid.
Can you try that in Express?
I think you are writing off the IDE far too quickly - all this functionality is available in pro but can't vouch for express; perhaps you should try adding a bunch of controls to a form and dragging them round holding keys like [ctrl] - you will probably find most of what you need is right under your fingertips it just different to other IDEs
Like Frederic suggests the options panel contains some settings for the designer. Also ShowGrid can help with visual cues.
However I recommend using a LayoutManager like the TableLayoutPanel or FlowLayoutPanel and using the docking/anchoring techniques which eliminate boring pixel perfection problems you'll get by doing the alignments yourself. I am of course assuming you're doing a "normal" winforms Form here...
Have a look at this MSDN article: http://msdn.microsoft.com/en-us/library/ms171689.aspx

Visual C# 2010 Express: Same Form But Different Size on Win7 and WinXP

I'm using Visual C# Express 2010 both on my Win7 and XP.
I have a Windows Form Application project, and there is SevenXPForm (inherits Form).
I created it in Visual C# Express 2010 on Win7, and in the Properties panel, I set
.MinimumSize = 300, 300
.Size = 300, 300
And a TabControl is in the middle of the Form:
However, when I save the project/solution, and open in in Visual C# Express 2010 on WinXP, the size changed to:
.MinimumSize = 300, 279
.Size = 300, 279
And the TabControl is NOT it the middle of the Form any more:
When I open it on Win7 again, it comes back.
This is haunting me, cuz my application is expected to be working both on XP and Seven, (and Vista).
Do I have to set something to let it behave exactly same both on Win7 and WinXP?
Peter
The problem you are seeing is that the borders around the form differ between Windows XP and Windows 7. This causes the window sizes to differ. How .NET tries to solve this is by instead of saving the size of the window as you see it in the property dialog, it actually saves the ClientSize, which is the inner size of the window. What you see in the property dialog is the size converted to include the outer borders. This means that when you open the project on Windows XP, which has smaller borders, .NET tries to adjust.
It looks like the problem you are seeing is an issue in the conversion. It does seem to take into account the smaller vertical size, but the smaller horizontal size is not taken into account.
Concerning your work around. A different approach to your specific problem/solution would be not to automatically resize the tab control, but to let .NET do this for you. If you set the Padding of the form to e.g. 10, 10, 10, 10 and set Dock of the tab control to Fill, you will get the same effect.
I don't see a general solution here though, because if this is an issue in the conversion that .NET itself does, this becomes very difficult.
After Googling a lot, I still cannot find a solution. But I do have a wordaround to partially solve my problem:
private void SevenXPForm_Load(object sender, EventArgs e)
{
tabControl1.Width = this.ClientSize.Width - tabControl1.Left * 2;
tabControl1.Height = this.ClientSize.Height - tabControl1.Top * 2;
}
This is just a workaround, I think there should be a better way to do.
(What if there are a lot of controls on the form? Of course, we can put a panel as the sole child control of the form, and then add all other controls into this panel, which works, but it's too tedious)
A more robust workaround is to put the contents of the entire form in a panel with the docking set to fill, and then line up everything as you otherwise would in that panel. Until this issue is fixed -- assuming that it ever is -- I'd recommend doing this as a matter of course for every form you create.
Please take a look on this link:
http://msdn.microsoft.com/en-us/library/ms229605.aspx
--
Quick View
Automatic scaling enables a form and its controls, designed on one machine with a certain display resolution or system font, to be displayed appropriately on another machine with a different display resolution or system font. It assures that the form and its controls will intelligently resize to be consistent with native windows and other applications on both the users' and other developers' machines. The support of the .NET Framework for automatic scaling and visual styles enables .NET Framework applications to maintain a consistent look and feel when compared to native Windows applications on each user's machine.
It's old question, but it is in Google, so I have an answer, which may be useful for others, so I will share it (sorry for my English).
1) draw a panel1
2) panel1.Dock = DockStyle.Fill in Form1_Load section;
3) now you can use panel1 width and height to get real width and height of Form1, no matter which OS (Win XP or 7) you are using, no matter form border style.

visual studio 2005 designer moves controls and resizes Form

When i open a form in visual studio 2005 (c#) the designer automaticaly resize the form and move/resize controls without touching the designer at all. The source file is changed and when i close the designer i'm asked to save the *.cs file.
I tried to look into visual studio options without any success.
any ideas?
visual studio setup or something?
thanks,
Tal
I have been working on this problem for most of today and found some interesting things: The main source of the problem seems to be relying on anchoring. If I use docking to position my controls, instead of anchoring, my problems seem to go away. I found a couple of blog posts from 2003(!), which detail how you might use docking instead of anchoring, and explain how anchoring can break the Windows Forms designer. It seems like this problem might be over 7 years old!
Here are the posts:
http://weblogs.asp.net/rweigelt/archive/2003/09/24/28984.aspx
http://weblogs.asp.net/rweigelt/archive/2003/10/17/32407.aspx
http://weblogs.asp.net/rweigelt/archive/2003/10/23/33181.aspx
This is due to AutoScaleMode-property. Your forms have probably been designed with a different DPI or Font settings than you have now in Windows display settings. AutoScaleMode-property has 4 different possible values : Dpi, Font, Inherit or None. In Dpi or Font mode, your forms and controls will be automatically resized depending on windows display settings.
So, set the AutoScaleMode-property to None in all your forms and controls and they won't be automatically resized anymore. Try to design your forms in order to let sufficient space in every controls so that text will fit even if text size is set to 125%.
I found a work around.
not sure what happens behind but i changed my display properties. and it works fine.
here is the sequence: display propertis->settings tab->advance.
in the the advance dialog i changed the "DPI Settings" from Large (120dpi) to Normal (96 dpi)
Had the same problem with controls anchored top, left and right within complex TabControls. The visual studio forms designer was increasing the width of all nested controls each time I would open the form.
I found a simple workaround thanks to this post. I simply added a panel to each tab and set their dock property to fill. All existing controls within the tabs were moved inside those panels. This works, even if the controls are anchored top, left and right.
Works at least for Visual Studio 2013 and 2015.
This is one you should live with. Even in VS2008 such things happen from time to time. It is mostly depends on form content (controls, positions, etc), and there is no option in VS to disable such behavior.
When you open your form in designer, vs runtime rebuilds visual appearance from code behind. And sometimes it made changes at this moment. Also when you are simply adding one control to form, designer fully rebuilds codebehind and resource files. This is well known issue, and seems that MS won't fix it, because they move in WPF direction.
So several points to simplify your life:
Move to VS2008, designer were more consistent, but still shuffle controls in .designer.cs file
Place your code in one of the source repositories, so if you accidentally saved such form, you can restore it from repositary.
Setting the form Min and Max size settings to the current size was a good work around for me. This prevented VS from resizing it.
I had a trivial form with few controls on it, where the OK and Cancel at the bottom were being shifted up as soon as the form was opened in the VS2013 designer. The same behaviour was observed in VS2015.
The accepted answer here of DPI did not solve the issue for me, nor were there any issues on the size of the form/padding/margins.
Removing the controls that are shifted and adding them back into the form solved the problem for me, as suggested by ptutt here:
Visual Studio designer moving controls and adding grid columns when form is opened
While I appreciate ryantum's suggestion and links of using docking [with panels], as also referred to in the link above with Roland's blog post here https://weblogs.asp.net/rweigelt/28984, with something so trivial I'd rather just make it go away with removing/adding back in.
I found locking the controls from the format menu was a simple and effective solution. VS2013
I had this problem with VS 2015.
I used dock panels with the controls that moved unexpectedly as their childs.
By default the controls will be aligned to the left, but you can change the orientation.
My buttons stopped moving.
I had this issue, too. Every time I opened the designer, every box with anchor "right" was moved about 20 Pixels to the left. Additionally, the bottom of every box with anchor "left" was about 200 pixels outside the form.
This form has many controls and should not shrink on smaller displays, so it was set to autoscroll, the form itself was smaller in the designer than the shown minimum size (historically...). I just set the size to the minimum size so that no scroll bars appeared in the designer and the anchors worked as expected without screwing up the postitions.
I read the first post from ryantm's answer which led me to the solution. Apparently it has something to do with the order .Net executes events such as setting the size of a form.

Categories