๐ฉ๐ป๐พ
[C#/WPF] ๋ฒํผ ๋ชจ์๋ฆฌ ๋ฅ๊ธ๊ฒ ๋ง๋ค๊ธฐ ๋ณธ๋ฌธ
์ด๋ฒ ํฌ์คํ ์์๋ ๋ฒํผ(Button)์ ๋ชจ์๋ฆฌ๋ฅผ ๋ฅ๊ธ๊ฒ ๋ง๋๋ ๋ฒ์ ๋ํด ์จ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
WPF์์ ๋ฒํผ์ ์ฒ์ ์์ฑ์, ์ด๊ธฐ ๋ชจ์๋ฆฌ๊ฐ์ 0์ผ๋ก ๊ฐ์ง ํํ์ ๋๋ค. ์ด๋, ๋ชจ์๋ฆฌ๋ฅผ ๋ฅ๊ธ๊ฒ ํด์ฃผ๋ ์์ฑ์ด ์๋๋ฐ์ ๋ฐ๋ก 'CornerRadius' ์ ๋๋ค. ์ด ์์ฑ์ ์์ฑ์ฐฝ์์๋ ์ฐพ์๋ณผ ์ ์๊ธฐ ๋๋ฌธ์ xaml์์ ์ฝ๋๋ก ์์ฑํด์ ๊ฐ์ ์ค์ ํด์ฃผ์ด์ผ ํฉ๋๋ค.
์ฐ์ , ๋ฒํผ์ ํ๋ ์์ฑํด์ค๋๋ค.
์ด์ xaml์์ ํด๋น ๋ฒํผ์ ๋ํ CornerRadius ์์ฑ๊ฐ์ ์ค์ ํด์ฃผ๋๋ก ํ๊ฒ ์ต๋๋ค.
<Button>์ <Button.Resources> ํ๊ทธ๋ฅผ ์ถ๊ฐํ๊ณ ํ๊ทธ ์์ TargetType์ ๋ชจ์๋ฆฌ๋ก ์ง์ ํด์ค๋๋ค. ๊ทธ๋ฆฌ๊ณ Property๋ฅผ CornerRadius๋ก ์ค์ ํ๊ณ ๊ฐ์ ์ ๋ ฅํด์ฃผ๋ฉด
์๋ ์ฌ์ง๊ณผ ๊ฐ์ด ๋ชจ์๋ฆฌ๊ฐ ๋ฅ๊ธ์ด์ง ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
์ด๋ ๊ฒ ํ๋์ ๋ฒํผ์ ๋ํ ์์ฑ์ ๋ณ๊ฒฝํ ๋๋ ํด๋น ๋ฒํผ์ ๋ฐ๋ก CornerRadius์ ์์ฑ์ ์ถ๊ฐํด์ฃผ๋ฉด ๋์ง๋ง, ๋ง์ฝ ๋ฒํผ ์ฌ๋ฌ๊ฐ์ ๊ฐ์ ์์ฑ๊ฐ์ ์ฃผ๊ธฐ ์ํด ๋ชจ๋ ๋ฒํผ์ ConerRadius์ ๋ํ ์ฝ๋๋ฅผ ์ฐ๊ฒ ๋๋ค๋ฉด
์ ์ฌ์ง์ฒ๋ผ ๋์ผํ ์ฝ๋์ ๋ฐ๋ณต๋ผ์ ์ฐ์ฌ์ ธ ์ฝ๋์ ๊ธธ์ด๊ฐ ๊ฝค ๋์ด๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
๊ทธ๋์ ๊ฐ์ ์์ฑ์ ๊ฐ์ง ๋๊ตฌ๋ฅผ ์ฌ๋ฌ๊ฐ ์์ฑํ๊ณ ์ถ์ผ๋ฉด ํด๋น ๋๊ตฌ์ ๋์์ธ์ ๋ฏธ๋ฆฌ ์ค์ ํด์ฃผ๋ฉด ์๋ ์ฌ์ง์ฒ๋ผ ๋ณด๋ค ๊น๋ํ๊ฒ ์ฝ๋๋ฅผ ์์ฑํ ์ ์์ต๋๋ค.
์ถ๊ฐ๋ก CornerRadius๋ฟ๋ง ์๋๋ผ ๋ค๋ฅธ ์์ฑ๊ฐ๋ ์ค์ ํด๋ณด์์ต๋๋ค.
+ ๋ง์ฐฌ๊ฐ์ง๋ก ToggleButton๋ ' Style TargetType = "{ x: ToggleButton }" '๋ก๋ง ์์ ํด์ฃผ๋ฉด Button ๊ฐ์ด ๋์ผํ๊ฒ ์ ์ฉํ ์ ์์ต๋๋ค.
์์ฑํ xaml ์ ์ฒด ์ฝ๋์ ๋๋ค.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <Window x:Class="Example.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Example" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Window.Resources> <Style TargetType="{x:Type Button}"> <Setter Property="Width" Value="180"/> <Setter Property="Height" Value="160"/> <Setter Property="FontFamily" Value="/Example;component/Font/#KNPS Kkomi"/> <Setter Property="FontSize" Value="35"/> <Setter Property="Background" Value="#FFDFE4E0"/> <Style.Resources> <Style TargetType="{x:Type Border}"> <Setter Property="CornerRadius" Value="20"/> </Style> </Style.Resources> </Style> </Window.Resources> <Grid> <Button Content="Button1" HorizontalAlignment="Left" Margin="191,30,0,0" VerticalAlignment="Top"/> <Button Content="Button2" HorizontalAlignment="Left" Margin="191,234,0,0" VerticalAlignment="Top"/> <Button Content="Button3" HorizontalAlignment="Left" Margin="440,30,0,0" VerticalAlignment="Top"/> <Button Content="Button4" HorizontalAlignment="Left" Margin="440,234,0,0" VerticalAlignment="Top"/> </Grid> </Window> | cs |
'Language > C#' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C#/WPF] ToggleButton ๋๋ฆผ ๊ฐ์ ์ ํํ๊ธฐ (0) | 2023.02.02 |
---|---|
[C#/WPF] ํ์ ๋ฉ์ธ์ง ๋์ฐ๊ธฐ (0) | 2023.02.01 |
[C#/WPF] ํ์ฌ ๋ ์ง์ ์๊ฐ ํ์ํ๊ธฐ (0) | 2023.01.27 |
[C#/WPF] ์ธ๋ถ ํฐํธ ์ ์ฉํ๊ธฐ (0) | 2023.01.27 |