PDA

View Full Version : textbox align



abi_sarab
دوشنبه 22 مهر 1387, 11:52 صبح
با سلام
چون کسی جوابمو نداد دوباره می پرسم
چه طور می شه متن توی تکست باکس را از هر دو طرف (چپ و راست) تراز کرد.
اگه دقت کرده باشید از یک طرف تراز هست ولی از طرف دیگه نیست.
مرسی

baran_mehr
دوشنبه 22 مهر 1387, 14:17 عصر
سلام داداش گلم.
منظورت چپ چین و راست چینه؟؟؟
اگر اینه خوب با خصوصیت TextAlign میتونید.

morteza_261
دوشنبه 22 مهر 1387, 16:35 عصر
با سلام
چون کسی جوابمو نداد دوباره می پرسم
چه طور می شه متن توی تکست باکس را از هر دو طرف (چپ و راست) تراز کرد.
اگه دقت کرده باشید از یک طرف تراز هست ولی از طرف دیگه نیست.
مرسی
سلام
وقتی TextAlign=Center باشه از دو طرف تراز هست!!!
ایام به کام

abi_sarab
دوشنبه 22 مهر 1387, 18:07 عصر
نه آقا این طوری که نمی شه.
باید از دو طرف تراز باشه.
وقتی راست چین می شه اصلاً کل متن می یاد وسط اگه ما تو یه خط 5 تا کلمه داشته باشیم. 5 تاش می یاد وسط

baran_mehr
دوشنبه 22 مهر 1387, 18:41 عصر
خوب داداش گلم شما درست نگفتید که چی میخواین یعنی منظورتون رو واضح نرسوندید چیه؟
اگر میخوای مثلا از اول یا اخرش Space وجود داشته باشه یعنی از دو طرف یه فاصله ای داشته باشه میتونی به دو طرف کاراکتر Space وارد کنی.
اگه منظورت اینه بگو تا کمکت کنم

mostafaaa
دوشنبه 22 مهر 1387, 18:56 عصر
سلام دوست من این چیزی رو که شما میخوای حالت Justify هستش که ادیتورهای مثل Word و WordPad دارن.
خود کنترلهای DotNet همچین امکانی رو ندارن ولی میتونی با استفاده از یک کلاس این کار رو انجام بدی.

Friend Class clsRichTextJustify

Private Const WM_USER As Short = &H400S
Private Const EM_EXSETSEL As Integer = (WM_USER + 55)
Private Const EM_SETSEL As Short = &HB1S
Private Const EM_GETSEL As Short = &HB0S
Private Const EM_GETPARAFORMAT As Integer = (WM_USER + 61)
Private Const EM_SETPARAFORMAT As Integer = (WM_USER + 71)
Private Const EM_GETSELTEXT As Integer = (WM_USER + 62)
Private Const EM_SETTYPOGRAPHYOPTIONS As Integer = (WM_USER + 202)
Private Const EM_GETTYPOGRAPHYOPTIONS As Integer = (WM_USER + 203)
Private Const TO_ADVANCEDTYPOGRAPHY As Short = &H1S
Private Const TO_SIMPLELINEBREAK As Integer = &H2
Private Const PFM_ALIGNMENT As Short = &H8S
Private Const PFM_TABSTOPS As Short = &H10S
Private Const PFM_STYLE As Short = &H400S
Private Const PFA_LEFT As Short = 1
Private Const PFA_RIGHT As Short = 2
Private Const PFA_CENTER As Short = 3
Private Const PFA_JUSTIFY As Short = &H4S
Private Const PS_SOLID As Short = 0
Private Const PFA_FULL_GLYPHS As Short = 7
Private Const mZERO As Integer = &H0
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal uMgs As Integer, ByVal wParam As Integer, ByRef lParam As PARAFORMAT2) As Integer 'I made change in this line _Lars9

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal uMgs As Integer, ByVal wParam As Integer, ByRef lParam As Charrange) As Integer 'I made change in this line _Lars9


Private Structure Charrange
Dim cpMin As Integer
Dim cpMax As Integer
End Structure



Private Structure PARAFORMAT2
Dim cbsize As Short
Dim dwpad As Short
Dim dwMask As Integer
Dim wNumbering As Short
Dim wReserved As Short
Dim dxStartIndent As Integer
Dim dxRightIndent As Integer
Dim dxOffset As Integer
Dim wAlignment As Short
Dim cTabCount As Short
<VBFixedArray(31)> Dim lTabstops() As Integer
Dim dySpaceBefore As Integer
Dim dySpaceAfter As Integer
Dim dyLineSpacing As Integer
Dim sStyle As Short
Dim bLineSpacingRule As Byte
Dim bOutlineLevel As Byte
Dim wShadingWeight As Short
Dim wShadingStyle As Short
Dim wNumberingStart As Short
Dim wNumberingStyle As Short
Dim wNumberingTab As Short
Dim wBorderSpace As Short
Dim wBorderWidth As Short
Dim wBorders As Short

Public Sub Initialize()
ReDim lTabstops(31)
End Sub
End Structure
Public Sub Justify(ByVal hwndr As IntPtr, ByRef intStart As Short, ByRef intEnd As Short)
Dim myparaf As PARAFORMAT2
Dim cr As Charrange
Dim lngRet As Integer
myparaf.cbsize = Len(myparaf)
' paragraph selection points to character before and
' character after position from beginning of the RichText Box
cr.cpMax = intEnd
cr.cpMin = intStart
' Select the text if you don't want to see it make the RichText invisible first
SendMessage(hwndr, EM_EXSETSEL, mZERO, cr)
lngRet = SendMessageLong(hwndr, EM_SETTYPOGRAPHYOPTIONS, TO_ADVANCEDTYPOGRAPHY, TO_ADVANCEDTYPOGRAPHY)

If lngRet = 1 Then 'only do this if version 3.0

lngRet = SendMessageLong(hwndr, EM_GETTYPOGRAPHYOPTIONS, mZERO, mZERO)
lngRet = SendMessage(hwndr, EM_GETPARAFORMAT, mZERO, myparaf)
If myparaf.wAlignment = PFA_LEFT Then
myparaf.dwMask = PFM_ALIGNMENT
myparaf.wAlignment = PFA_JUSTIFY

lngRet = SendMessage(hwndr, EM_SETPARAFORMAT, mZERO, myparaf)
Else
System.Diagnostics.Debug.WriteLine("Centre")
End If
Else
System.Diagnostics.Debug.WriteLine("FAIL")
End If
cr.cpMin = 0
cr.cpMax = 0
SendMessage(hwndr, EM_EXSETSEL, mZERO, cr)
End Sub


Public Sub Settabs(ByVal hwndr As IntPtr, ByRef lngArrTabs() As Integer, ByRef rwidth As Integer, Optional ByRef lngstart As Integer = 0, Optional ByRef lngEnd As Integer = 0)
'sets tabs in twips careful not to exceed the width of the rich text box rwidth
' pass in the tabs in an array base 1
Dim myparaf As PARAFORMAT2
Dim lngRet As Integer
Dim intCnt As Short
Dim cr As Charrange
Dim intCum As Short
Dim lngTabs As Integer
lngEnd = lngEnd + 4
'set the selection
If lngstart = 0 And lngEnd = 0 Then
'cr.cpMax = Len(frmName.richtb.Text) 'put appropriate source in here
cr.cpMin = 0
Else
cr.cpMax = lngEnd
cr.cpMin = lngstart
End If

'first select all the text or nothing will happen
SendMessage(hwndr, EM_EXSETSEL, 0, cr)

'setup the tab array
lngTabs = UBound(lngArrTabs)
myparaf.cbsize = Len(myparaf)
lngRet = SendMessage(hwndr, EM_GETPARAFORMAT, 0, myparaf)

For intCnt = 0 To lngTabs - 1
If lngArrTabs(intCnt + 1) <= rwidth Then '(rwidth * Screen.TwipsPerPixelX) - lngSize Then
myparaf.lTabstops(intCnt) = lngArrTabs(intCnt + 1)
myparaf.cTabCount = intCnt + 1
End If
Next intCnt

'Now do the tabs
myparaf.dwMask = PFM_TABSTOPS
lngRet = SendMessage(hwndr, EM_SETPARAFORMAT, 0, myparaf)
cr.cpMax = 0
cr.cpMin = 0

'clean up setting selection to zero
SendMessage(hwndr, EM_EXSETSEL, 0, cr)
End Sub
End Class
در ضمن به جای TextBox از RichTextBox استفاده کن.

abi_sarab
سه شنبه 10 دی 1387, 09:53 صبح
آقا مصطفی مرسی ولی این کار نمی کنه! یعنی وقتی ما richtextbox رو right to left می کنیم. دیگه کار نمی کنه.