1. WPF Layout - Grid
import clr
clr.AddReference("PresentationFramework")
clr.AddReference("PresentationCore")
from System.Windows import *
from System.Windows.Controls import *
from System.Windows.Media.Effects import *
def GetButton(title,size,handler):
l = Button()
l.Content = title
l.FontSize = size
l.Margin = Thickness(5)
l.Padding = Thickness(5)
l.HorizontalAlignment = HorizontalAlignment.Center;
l.VerticalAlignment = VerticalAlignment.Center;
l.Click += ClickEvent
return l
def ClickEvent(sender,args):
MessageBox.Show(sender.Content,"Alert")
def GetGrid(row,col):
g = Grid()
#g.Width = 320
#g.Height = 240
g.HorizontalAlignment = HorizontalAlignment.Stretch
g.VerticalAlignment = VerticalAlignment.Stretch
g.ShowGridLines = True
for c in range(col):
g.ColumnDefinitions.Add(ColumnDefinition())
for r in range(row):
g.RowDefinitions.Add(RowDefinition())
return g
if __name__ == "__main__":
w = Window()
w.Title = "Hello World"
w.Width = 320
w.Height = 240
g = GetGrid(3,4)
for r in range(3):
for c in range(4):
b = GetButton(str(r) + str(c), 16, ClickEvent)
g.SetRow(b,r)
g.SetColumn(b,c)
g.Children.Add(b)
w.Content = g
Application().Run(w)
2. WPF Layout - Grid Span
import clr
clr.AddReference("PresentationFramework")
clr.AddReference("PresentationCore")
from System.Windows import *
from System.Windows.Controls import *
from System.Windows.Media.Effects import *
def GetButton(title,size,handler):
l = Button()
l.Content = title
l.FontSize = size
l.Margin = Thickness(5)
l.Padding = Thickness(5)
l.HorizontalAlignment = HorizontalAlignment.Stretch;
l.VerticalAlignment = VerticalAlignment.Stretch;
l.Click += ClickEvent
return l
def ClickEvent(sender,args):
MessageBox.Show(sender.Content,"Alert")
def GetGrid(row,col):
g = Grid()
#g.Width = 320
#g.Height = 240
g.HorizontalAlignment = HorizontalAlignment.Stretch
g.VerticalAlignment = VerticalAlignment.Stretch
g.ShowGridLines = False
for c in range(col):
g.ColumnDefinitions.Add(ColumnDefinition())
for r in range(row):
g.RowDefinitions.Add(RowDefinition())
return g
if __name__ == "__main__":
w = Window()
w.Title = "Hello World"
w.Width = 320
w.Height = 240
g = GetGrid(3,4)
for r in range(3):
for c in range(4):
b = GetButton(str(r) + str(c), 16, ClickEvent)
g.SetRow(b,r)
g.SetColumn(b,c)
if r == 0 and c == 0:
g.SetColumnSpan(b,4)
g.Children.Add(b)
break
else:
g.Children.Add(b)
w.Content = g
Application().Run(w)
3. WPF Layout - Grid Column/Row Definition
import clr
clr.AddReference("PresentationFramework")
clr.AddReference("PresentationCore")
from System.Windows import *
from System.Windows.Controls import *
from System.Windows.Media.Effects import *
def GetButton(title,size,handler):
l = Button()
l.Content = title
l.FontSize = size
l.Margin = Thickness(5)
l.Padding = Thickness(5)
l.HorizontalAlignment = HorizontalAlignment.Stretch;
l.VerticalAlignment = VerticalAlignment.Stretch;
l.Click += ClickEvent
return l
def ClickEvent(sender,args):
MessageBox.Show(sender.Content,"Alert")
def GetGrid(row,col):
g = Grid()
g.HorizontalAlignment = HorizontalAlignment.Stretch
g.VerticalAlignment = VerticalAlignment.Stretch
g.ShowGridLines = False
return g
if __name__ == "__main__":
w = Window()
w.Title = "Hello World"
w.Width = 320
w.Height = 240
g = GetGrid(2,3)
g.ColumnDefinitions.Add(ColumnDefinition(Width=GridLength(60)))
g.ColumnDefinitions.Add(ColumnDefinition(Width=GridLength(1,GridUnitType.Star)))
g.ColumnDefinitions.Add(ColumnDefinition(Width=GridLength(60)))
g.RowDefinitions.Add(RowDefinition(Height=GridLength(1,GridUnitType.Auto)))
g.RowDefinitions.Add(RowDefinition(Height=GridLength(1,GridUnitType.Star)))
b = GetButton("00", 16, ClickEvent)
g.SetRow(b,0)
g.SetColumn(b,0)
g.Children.Add(b)
b = GetButton("01", 16, ClickEvent)
g.SetRow(b,0)
g.SetColumn(b,1)
g.Children.Add(b)
b = GetButton("02", 16, ClickEvent)
g.SetRow(b,0)
g.SetColumn(b,2)
g.Children.Add(b)
b = GetButton("10", 16, ClickEvent)
g.SetRow(b,1)
g.SetColumn(b,0)
g.SetColumnSpan(b,3)
g.Children.Add(b)
w.Content = g
Application().Run(w)
댓글 없음:
댓글 쓰기