How to retrieve screen size/resolution in MS Access VBA to re-size a form - forms

I have two popup forms (parent/child) that I want to be able to automatically re-size depending on the size of the screen.
How can I retrieve the size of the screen in order to achieve this.

For Access 2010 64 bit, you will need to add PtrSafe before Function.
Declare Function GetSystemMetrics32 Lib "User32" _
Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
Sub ScreenRes()
Dim w As Long, h As Long
w = GetSystemMetrics32(0) ' width in points
h = GetSystemMetrics32(1) ' height in points
End Sub
More info: http://support.microsoft.com/kb/210603

For VBA, a simpler (and therefore possibly more portable) solution might be:
Application.UsableHeight
Application.UsableWidth
As found at Adjust userforms to fit in screen. I am using this successfully with Word 2007 VBA. In my case, Application.UsableWidth gives the actual screen width, Application.UsableHeight gives the actual screen height, minus the height of Windows' taskbar.

Related

VISIO - How to set grid lines such that each character appears in 1 square and each square contains only 1 character using fixed font

What I am trying to do is to enable the user to fill a report design form using fixed font. Only older people have seen such forms for coding and report design :)
Question:
Using VISIO, how to set grid lines such that each character appears in 1 square and each square contains only 1 character using a fixed font such as Courier New? I am open to completely different approaches if any, even if it involves coding in VBA or C#, I know some.
I tried different values for "Minimum Spacing" but I can't get the desired result.
EDIT
I also attempted to place a grid image in the background and put the textbox in front, still monospaced font characters overlap with lines...
Edit I also tried this VBA Code:
Sub Test()
Dim I As Integer
Dim D As Double
Dim X1 As Double
Dim Y1 As Double
D = 0.13
X1 = 1.373
Y1 = 10.04
For I = 1 To 20
Application.ActiveWindow.Page.DrawLine X1, Y1, X1, Y1 + 1
X1 = X1 + D
Next
End Sub
Which produced the following "bad" result - All this suggests the the implementation of Courier New is not really fixed in width!
The Visio grid doesn't work in that way. You need to use a proper grid shape. There is one at More Shapes -> Business -> Charts and Graphs -> Charting Shapes. Set the columns and rows to what you need and then resize.
Example here - using font Liberation Mono.

Scale text to fit in a box

I'm working on a matlab GUI and I am trying to make the text font size resize to boxes. Currently I have a few solutions, but they aren't optimal. The fastest one is scaling the text by a goal/Extent factor:
goal = [0 0 .9 .9].*b.Position
fs = b.FontSize*min(goal./b.Extent)
b.FontSize = fs;
b is the uicontrol element. This works, but if the text is too long and needs to wrap it won't, and it will rather shrink the height until it fits on one line in the box.
I also have a while loop approach that * or /s by .99 until extent and goal are close enough.
What I've been looking for is an approach that will wrap the text so that I display the whole string but also take advantage of the whole space. I also had a recursive backtracking attempt that would try to find the best ratio the words would have to the ratio of the sides of the box, but that takes O(2^n) which is good to avoid.
Online I found the textwrap function, but I think that depends on font size, so it doesn't help me. Any ideas on how to do this?
maybe you can load your text as an image, instead of using labels use an axis and load the image o your desired text. Next time you wanted to resize your figure you won't be worry about it.

matlab: having a good control of MyBox, box with text

my problem is I want to have a box for additional bigger comments to the graph.
How can I create this box, so that it will be always on the right bottom side outside of my graph, and it will be automatically adjusting its size to the amount of text inside? Also, if I will have longer text, I need it to be split into more lines, not just one line extremely long.
I use it like that, however I have a poor control over what is happening, this just creates a certain size in a certain place, text is cut.. please help :)
x = rand(110)*100;
y = x;
plot(x,y)
MyBox = uicontrol('style','text')
set(MyBox,'String','optional longer information to be put into diagram')
set(MyBox,'Position',[10,0,40,10])
I am afraid you can not do that automatically - Text boxes do not use callbacks. From the documentation:
Users cannot change static text interactively. Static text controls do not activate callback routines when clicked.
What you can do is call textwrap function, which will automatically wrap the text you pass to it and return new Text box position:
MyBox = uicontrol('style','text');
% set initial position - first three values are kept constant after wrap, the hight can be changed
set(MyBox,'Position',[10,10,30,10])
% adjust the height of your Text box and wrap the text
[outstring,newpos] = textwrap(MyBox,{'optional longer information to be put into diagram'});
% set new position and text
set(MyBox,'Position',newpos, 'String', outstring)
You will have to call textwrap and set(...) yourself whenever you change the string in the text box.

Can width/height of a powerpoint presentation be calculated on iPad

I have an ipad app, which displays a powerpoint presentation from an NSData, within a UIWebView, and I need to know the width/height of a single slide so I know how far to scroll when advancing to the next slide.
In PDF, I can calculate it using CGPDFDocumentRef, as below, but I can't find a corresponding API for powerpoint, and since it's a microsoft format, I doubt it even exists.
I can use javascript to determine the width/height of the ENTIRE presentation, but that doesn't help me know how far to advance to go one single slide,
Code to do what I need to for a PDF:
CFDataRef myPDFData = (CFDataRef)presentationContent;
CGDataProviderRef provider = CGDataProviderCreateWithCFData(myPDFData);
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithProvider(provider);
CGPDFPageRef page = CGPDFDocumentGetPage(pdf, 1);
CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
int pageHeight=(int)pageRect.size.height;
int pageWidth=(int)pageRect.size.width;
//now I can advance to the proper page by doing a scrollto pageHeight*currentPage
Figured it out.
In this case, the UIWebView acts as if it's an iFrame on an HTML page, which has a source of some powerpoint file. So, there are certain things you can do to it, and certain properties that are exposed.
I found that document.all (an array) has elements - LOTS of elements. My 20 page powerpoint test file had over 300 elements. Looking at width / height of them was not overly helpful - some were the dimensions of the iframe itself, some were the dimensions from top-left pixel of slide 1 to bottom-right pixel of slide N, some were 0x0, and some (burried in the middle) were the dimensions of a slide. The pattern I found was that you have to skip the first element in document.all, and iterate through until you found one with non-zero width/height, who have identical values for clientHeight, offsetHeight, scrollHeight, as well as identical values for clientWidth, offsetWidth, and scrollWidth. The first one of these will give you the height/width of a single slide, and you can go from there. And, of course, because you're using a UIWebView, and only have stringByEvaluatingJavaScriptFromString to work with, you need to do this all in one line of javascript that returns the value.
So, to extract width/height of a powerpoint presentation, you can write:
NSString *w=[webview stringByEvaluatingJavaScriptFromString:#"function x(){var rtn='';for (var i=1;i<document.all.length;i++){var a=document.all[i];if (((a.clientWidth>0)&&(a.clientHeight>0))&&(a.scrollHeight.toString()==a.offsetHeight.toString())&&(a.offsetHeight.toString()==a.clientHeight.toString())){return ''+a.offsetWidth; }}return rtn;};x();"];
NSString *h=[webview stringByEvaluatingJavaScriptFromString:#"function x(){var rtn='';for (var i=1;i<document.all.length;i++){var a=document.all[i];if (((a.clientWidth>0)&&(a.clientHeight>0))&&(a.scrollHeight.toString()==a.offsetHeight.toString())&&(a.offsetHeight.toString()==a.clientHeight.toString())){return ''+a.offsetHeight; }}return rtn;};x();"];
and do whatever you need to with width/height from that point on.
Oh, and document.all isn't populated immediately once your document is loaded - UIWebView seems to need a few milliseconds to gather that and make it available. I run this 1 second after my webview has finished loading, and it works great on both ppt and pptx files. it does NOT work on pdf, though.
amongst others, these objects contain width and height properties:
Sub Test()
Dim A As Application
Set A = Application
Debug.Print A.Width, A.Height
Debug.Print A.Windows(1).Width, A.Windows(1).Height
Debug.Print A.SlideShowWindows(1).Width, A.SlideShowWindows(1).Height
End Sub
The most suitable for you seems to be the last one.
Results for a 1680 x 1050 screen
PPT in full-screen
1266 793,5
1245,75 699,75
1260 787,5
PPT in ca. 1/2 of screen
711,75 551,25
691,5 457,5
1260 787,5 <-- same as above as slideshows always go full-screan at the selected aspect ratio

Vista and Windows 7 borders cut off form content

Forms on Windows 7 and Vista have thicker borders than those of XP. As a result, some content that spans the entire height or width of a form will be cut off. Is there a simple way to fix this, or do all the forms of my application need to be resized to accommodate for this?
Update: It appears to be the fault of the form size and not the borders that are causing the problem. See the following images for an example. Notice how the controls have the correct location at the top-right corners, but they reach the each of the form in Windows 7 while a border is retained in XP. The same code is used to resize and position the controls.
Here's what a form looks like in XP:
alt text http://img504.yfrog.com/img504/1328/bordersxp.png
You should fix the size of the form programatically, to make sure the client size is big enough to fit everything. You can easily calculate the difference between the current size and client size of the form, and increase/decrease by the right amount.
You probably want to perform this inside Form_Load.
In VB6, the client size and width are referred to as ScaleWidth and ScaleHeight for forms. Setting these values just messes up the scaling, rather than resizing the form, so you instead have to do calculations so you can set the normal Width and Height properties.
BorderSize = Me.Width - Me.ScaleWidth
Me.Width = BorderSize + CorrectScaleWidth
//Same for height!