作成日: 2021/12/28 最終更新日: 2021/12/28
文書種別
使用方法
詳細
本コンポーネントには、コントロールの形を角丸表示させるための機能は用意されておりません。
代替策としてC1TextBoxコントロールを継承したカスタムコントロールを作成し、コントロールに関連付けられたウィンドウの形を角丸で描画する方法が考えられます。
以下に、カスタムコントロールのサンプルコードを記載します。
※ただし、コントロール枠は描画されませんので、ご了承ください。
◎サンプルコード(C#)
以下のサイトから、サンプルプロジェクトをダウンロード可能です(英語版のフォーラム)。
C1Textbox, how to make rounded corners?
代替策としてC1TextBoxコントロールを継承したカスタムコントロールを作成し、コントロールに関連付けられたウィンドウの形を角丸で描画する方法が考えられます。
以下に、カスタムコントロールのサンプルコードを記載します。
※ただし、コントロール枠は描画されませんので、ご了承ください。
◎サンプルコード(C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace RoundedCorners_C1TextBox
{
public partial class CustomC1TextBox : C1.Win.C1Input.C1TextBox
{
int _radius = 20;
int _opacity = 125;
Color _backColor = Color.Black;
public CustomC1TextBox()
{
InitializeComponent();
this.BackColor = Color.White;
this.Padding = new Padding(3, 0, 3, 0);
}
[System.Runtime.InteropServices.DllImport("gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect, // X-coordinate of upper-left corner or padding at start
int nTopRect, // Y-coordinate of upper-left corner or padding at the top of the textbox
int nRightRect, // X-coordinate of lower-right corner or Width of the object
int nBottomRect, // Y-coordinate of lower-right corner or Height of the object
// RADIUS, how round do you want it to be?
int nheightRect, // height of ellipse
int nweightRect // width of ellipse
);
protected override void OnCreateControl()
{
base.OnCreateControl();
this.Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(3, 3, this.Width, this.Height, 5, 5)); //play with these values till you are happy
}
}
}
以下のサイトから、サンプルプロジェクトをダウンロード可能です(英語版のフォーラム)。
C1Textbox, how to make rounded corners?