Solved

Text alignment in usercontrol

Posted on 1998-06-14
12
483 Views
Last Modified: 2008-02-01
I have created a simple usercontrol that only uses a textbox. I have full control over most of the textbox's properties EXCEPT text alignment which appears to be read only. Is there a API to force this?
0
Comment
Question by:entretec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +2
12 Comments
 

Author Comment

by:entretec
ID: 1463289
Adjusted points to 100
0
 
LVL 1

Expert Comment

by:redbaron082997
ID: 1463290
How are you implementing the text box functions? alignment is not read-only, that is the property that you set for center,left,etc.  You may need to implement it as such:

property let alignment( pos as single)
  textbox1.alignment = pos
end property
0
 

Expert Comment

by:topol
ID: 1463291
I think if it is read-only API won't work either. What you can do is to insert extra spaces based on alignment--if it is cenrered, you find out the length of textbox, the length of text in text box and insert spaced there.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:entretec
ID: 1463292
The text alignment is read only which is strange because this property CAN be changed in the native textbox.
I thought of shadowing the textbox with a couple of others that had the alternative alignments but I need the textbox to be databound and that seems a contorted thing to try and code safely
I will try topol's suggestion to see if this would work.
0
 
LVL 1

Expert Comment

by:redbaron082997
ID: 1463293
have you tried impleming the above function as part of your new control? I just did it and Did not have a problem.  What does the code look like in your modules for declaring the functions of TextBox? Unless you have a property Let, it will be read-only.
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1463294
entreytec,
You need to have the multiline property set to true before your textbox's align property work. This may be the reason it is read only.
0
 

Author Comment

by:entretec
ID: 1463295
Perhaps I am not making myself clear. I want to able to alter the alignment from MY usercontrol in the properties menu or even programmaticaly. The nearest I can get is to have 2 separate usercontrols, one left justified and one right justified (too much of kludge, all the code has to be duplicated - I could have a module but how would you pass a usercontrol to it!). I have tried packing with spaces but it doesn't handle properly.

The following is how I have declared the property and functions

'''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub UserControl_InitProperties()
   Text1.alignment = vbLeftJustify
   '' other stuff
end sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Text1.alignment = PropBag.ReadProperty("alignment", vbLeftJustify)
'' other stuff

end sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    Call PropBag.WriteProperty("alignment", Text1.alignment, vbLeftJustify)
    '' other stuff
End Sub


Public Property Get alignment() As AlignmentConstants
    alignment = Text1.alignment
End Property

Public Property Let alignment(ByVal vNewValue As AlignmentConstants)
   Text1.alignment() = New_TabValue
   PropertyChanged "alignment"
End Property
0
 

Expert Comment

by:topol
ID: 1463296
So what doesn't work? Show your alignment code
0
 
LVL 2

Accepted Solution

by:
Llandr earned 120 total points
ID: 1463297
OK Here comes an answer.
UserControls cannot perform actions that involves destruction of a window (in the Windows-API meaning). This means that you cannot perform the rightalignment (since this operation involves deletion and creation of a new textbox window) another property that is impossible to export this way is the MultiLine property.

I made a work around which involves having two textboxes (both multiline) one right aligned and one left-aligned. Hide the textbox that is not currently visible. When you switch aligments copy properties betweeen the textboxes and show the relevant one.

0
 

Author Comment

by:entretec
ID: 1463298
Thanks if only to know it cannot be done. I would interested to see your work around
0
 
LVL 2

Expert Comment

by:Llandr
ID: 1463299
Give me an email and I will post the control to you.
0
 

Author Comment

by:entretec
ID: 1463300
I think I may have done the wrong thing and put my email on the question page. Here is my email mikeb@entretec.com.au
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question