Visual Basic 6

Individelle Message-Boxen

VB Nachrichten aufgebohrt

Die Standard Message-Box unter VB, die man über die Funktion MsgBox aufrufen kann, um dem Benutzer etwas mitzuteilen oder ihn etwas zu fragen lassen manchmal etwas zu wünschen übrig. So stehen nur 6 verschiedene Schaltflächenbeschriftungen zur Verfügung auf die man jedoch keinen Einfluss hat: Ja, Nein, OK, Abbrechen, Wiederholen und Ignorieren, was diese Funktion nicht gerade sehr flexibel macht. In dem meisten Fällen genügt das auch, aber eben nur in den meisten. Will man dem Benutzer andere Optionen bieten, muss ein eigenes Formular ran.

Meine Intention bei der Programmierung dieses Codes war, eine Message-Box zu bauen, die genauso aussieht wie das Original und sich ebenso verhält, aber eben mit frei definierbaren Schaltflächenbeschriftungen.

Die Form ist schnell erstellt. Man benötigt nur drei Schalflächen, ein Label-Element, in Image-Element, sowie eine Image-List, in der die vier möglichen Bilder für die Symbole "Frage", "Information", "Hinweis" und "kritischer Hinweis" abgelegt sind. Die Form erhält zudem folgende Eigenschaften:

  • Property Let Title (Titel der Form)
  • Property Let Message (anzuzeigende Nachricht)
  • Property Let Symbol (Long-Wert des anzuzeigenden Symbols)
  • Property Let DefaultButton (welche Schaltfläche erhält den Focus)
  • Property Let Button1 (Beschriftung der ersten Schaltfläche)
  • Property Let Button1 (Beschriftung der zweiten Schaltfläche)
  • Property Let Button1 (Beschriftung der dritten Schaltfläche)

Um während der Programmierung einer Anwendung sich nicht um die Form kümmern zu müssen, gibt es eine aufrufende Funktion, deren Parameter und Namen sich an das Original anlehnt: MsgBoxEx.

Public Function MsgBoxEx( _
   strMessage As String, _
   lngSymbol As enMsgSymbol, _
   strButton1 As String, _
   Optional strButton2 As String, _
   Optional strButton3 As String, _
   Optional intDefaultButton As Integer, _
   Optional strTitle As String) As Integer

   Dim frm As New frmMsgBox

   frm.Message = strMessage
   frm.Symbol = lngSymbol
   frm.DefaultButton = intDefaultButton
   If Len(Trim$(strTitle)) = 0 Then strTitle = App.Title
   frm.Title = strTitle
   frm.Button1 = strButton1
   frm.Button2 = strButton2
   frm.Button3 = strButton3

   frm.Show vbModal

   MsgBoxEx = pintMsgBoxExReturn

End Function

Der Einfachheit halber existiert die globale Variable pintMsgBoxExReturn, die im Code der Form gesetzt wird, je nachdem welche Schaltfläche gedrückt wurde, und den Rückgabewert der Funktion darstellt.

Eines der Probleme bestand nun darin den übergebenen Text und die Schaltflächen mit ihrer benutzerdefinierte Beschriftung einigermaßen ansehnlich auf die Form zu bekommen. Dabei sollten die Seitenabstände, ebenso wie die Schaltflächen und der Text selbst, akkurat und gleichmäßig aussehen, was bei der zumeist verwendeten Schriftart "MS Sans Serif" nicht trivial ist, denn die einzelnen Buchstaben haben nicht die gleiche Laufweite. Aus diesem Grund war die Hilfsfunktion CalcStringLenght vonnöten, die anhand der durchschnittlichen Laufweite der Buchstaben die Länge eines Textes in Twips errechnet:

Public Function CalcStringLenght( _
   ByVal strValue As String, _
   Optional ByVal lngMinimum As Long) As Long

   'Längenermittlung in Twips für die Schriftart "MS Sans Serif"

   Dim i As Integer
   Dim lngLen As Long

   For i = 1 To Len(strValue)

      Select Case Mid(strValue, i, 1)
         Case "i", "j", "l", "'"
            lngLen = lngLen + 420
         Case " "
            lngLen = lngLen + 450
         Case "f", "r", "t", "I", "!", "(",")"
            lngLen = lngLen + 570
         Case ",", ".", ";", ":", "-"
            lngLen = lngLen + 570
         Case "*"
            lngLen = lngLen + 720
         Case "s", "x", "y", "z", "J"
            lngLen = lngLen + 870
         Case "a", "b", "d", "e", "h", "k","n", "o", "p", "q"
            lngLen = lngLen + 1020
         Case "u", "v", "F", "L", """","\", "/"
            lngLen = lngLen + 1020
         Case "0", "1", "2", "3", "4", "5","6", "7", "8", "9", "_", "+", "="
            lngLen = lngLen + 1020
         Case "c", "A", "B", "C", "E", "K","P", "S", "T", "V", "X", "Y", "Z"
            lngLen = lngLen + 1170
         Case "m", "w", "D", "G", "H", "N","O", "Q", "R", "U", "%"
            lngLen = lngLen + 1320
         Case "M"
            lngLen = lngLen + 1470
         Case "W"
            lngLen = lngLen + 1470
         Case Else
            lngLen = lngLen + 1000
      End Select

   Next

   CalcStringLenght = lngLen / 10

   If CalcStringLenght < lngMinimum Then
      CalcStringLenght = lngMinimum
   End If

End Function

Mit dieser Funktion lässt sich nun beim OnLoad-Event der Form (kompletter Code siehe Download) die korrekte Breite der einzelnen Schaltflächen bestimmen. Die Breite und die Höhe der Message-Box ist jedoch vor allem abhängig vom darzustellenden Text, d.h von der Zeilenanzahl und der maximalen Zeilenlänge. Aus diesem Grund wird der Text zunächst an eventuell vorhandenen Zeilenumbrüchen auseinander geschnitten. Jedes der Teile wird in einzelne Worte zerlegt und über eine Schleife wird für jedes Wort die Länge in Twips errechnet und mit dem Text eine Zeile zusammengebaut, bis die maximale Zeilenlänge erreicht ist.

Aus der sich so ergebenden Zeilenanzahl und der maximalen Zeilenlänge wird die Breite und die Höhe der Form und des Label-Elements errechnet. Die Anzahl der anzuzeigenden Schaltflächen richtet sich danach, welchen Button-Eigenschaften Werte zugewiesen wurden. Diese werden dann am unteren Rand der Form zentriert angebracht.

Downloads

MsgBoxEx.zip
kick it on dotnet-kicks.de AddThis 0 wikio-Stimme(n) Trackback-Url...

69 Kommentare bislang...

  • mac cosmetics online
    Oakley Dispatch Sunglass
    Oakley Impatient Sunglasses
    buy mac cosmetics
    Oakley Radar Sunglasses
    Oakley Fuel Cell Sunglass
    Oakley Jupiter Sunglasses
    MAC Foundation
    Oakley Antix Sunglass
    69
    mac cosmetics online : Donnerstag, 10. Mai 2012 02:16
  • 68
    watches : Freitag, 27. April 2012 04:28
  • 67
    watches : Freitag, 27. April 2012 04:27
  • They hired a life Coach Factory Online expecting a quick fix, someone to simply make it all Coach Factory Store, and a life coach simply can not do that. So if you're looking at a life Louis Vuittonas an easy substitute for a Coach Outlet, you would be better off not hiring Burberry Scarf because it won't help you at all.So now that you know what a personal life Coach Factory Online does, how do you know if it's worth it to hire Louis Vuitton Handbags? You should take a good Coach Factorylook at your life and see if you have some life issue holding you back. If so, and if you're ready to work on it in order to better Louis Vuitton Purses, hiring a personal life Coach Factory Outlet may be a wonderful idea. If you're comfortable in your life, and not really ready to face uncomfortable issues that could be keeping you back, then Louis Vuitton Outlet hiring a personal life Coach Factory Outlet isn't for you. It could even be possible that a life coach manages to help you get to the point where you accept that you need work. In such a Coach Factory Outlet Online, the life coach ends up being very helpful! It seems as though everyone is looking for a sale or special, and when they find a bargain they love to tell everyone about it.
    66
    Coach Factory Online : Freitag, 23. März 2012 12:44
  • <p><strong><a href="http://www.replicalouisvuittonmall.com/">Louis Vuitton bags</a> </strong>Of which appears to be very affordable. Numerous Louis Vuitton tote bags include shielding plastic-type stuff over the attends to in the event there're service provider new <strong><a href="http://www.replicalouisvuittonmall.com/">Louis Vitton bags</a> </strong>almost all reselling insurers aren't going to be. If you are take possesses absolutely appeared put on or maybe was obviously a check out form that plastic-type ought to <strong><a href="http://www.replicalouisvuittonmall.com/">Louis Vuitton shoes</a> </strong>definitely not now there. Simply because there is absolutely no a really area <strong><a href="http://www.replicalouisvuittonmall.com/">Louis Vuitton speedy</a> </strong>due to the fact Louis Vuitton low cost take into consideration where by the seller received some <strong><a href="http://www.replicalouisvuittonmall.com/">Louis Vuitton Wallet</a> </strong>sort of take if a terrible is usually to this day interior grips. low cost louis <strong><a href="http://www.replicalouisvuittonmall.com/">Louis Vuitton vernis</a> </strong>vuitton clutches allow you to be delighted. Doc Everywhere you go Almost all knockoffs already <strong><a href="http://www.replicalouisvuittonmall.com/">replica Louis Vuitton Wallet</a> </strong>have document over the technology to defend the item. Of which <strong><a href="http://www.replicalouisvuittonmall.com/">replica Louis Vuitton bags</a> </strong>Alma service delivers doc from the zipper forces together with refers to thus you possibly view <strong><a href="http://www.replicalouisvuittonmall.com/">cheap Louis Vuitton</a> </strong>numerous in conjunction with doc many of-all in excess of every stud. The <strong><a href="http://www.replicalouisvuittonmall.com/">cheap Louis Vuitton bags</a> </strong>value only 1 when using the suitable strategy of considering should some sort of tote is frequently <strong><a href="http://www.replicalouisvuittonmall.com/">Louis Vuitton</a> </strong>manufactured will be by means of trying to find interior sale price. In the event the <strong><a href="http://www.replicalouisvuittonmall.com/">Louis Vuitton replica handbags</a> </strong>item sincerely is in relation to 50% a reduced amount of when compared with purchase with the <strong><a href="http://www.replicalouisvuittonmall.com/">Louis Vuitton canvas bags</a> </strong>equivalent life of the loan in an Louis Vuitton dealer it is usually ones counterfeited.</p>
    65
    Louis Vuitton bags Of which appears to be very affordable. Numerous Louis Vuitton tote bags include shielding plastic-type stuff over the attends to in the event there're service ">Louis Vuitton bags : Freitag, 2. März 2012 07:39

Dein Kommentar hierzu...


Kommentar-Feed für diesen Beitrag
Gravatare werden unterstützt .:. eMail-Adressen werden nicht veröffentlicht
 

RSS-Feed

Die URL des Standard-Newsfeed von zerbit.de lautet:

http://www.zerbit.de/rssfeed.aspx

Login


 

 

Statistik



kürzlich kommentiert

Artikel 13

  • Datum: 08.03.2005
    Kategorie: Visual Basic 6
    Zugriffe: 3.153
    Kommentare: 69
    Trackbacks: 0

Letzte Beiträge

Kategorien

Buttons & More

Blog-Roll

Banner Piraten-Partei