! 제품 버전을 정확하게 입력해 주세요.
제품 버전이 정확하게 기재되어 있지 않은 경우,
최신 버전을 기준으로 안내 드리므로
더욱 빠르고 명확한 안내를 위해
제품 버전을 정확하게 입력해 주세요!

하나의 셀안에 버튼과 텍스트 표시 문의 > Q&A | 토론

본문 바로가기

WinForms윈폼 하나의 셀안에 버튼과 텍스트 표시 문의

페이지 정보

작성자 ReAzN 작성일 2023-05-19 12:48 조회 736회 댓글 1건
제품 버전 : spreadv15

본문

안녕하세요


 


하나의 셀에서 위 첨부 사진과 같이 셀내용을 표시하고 버튼도 한쪽구석에 표현하고 싶은데 해당 기능이 현재 지원이 되나요? 

지원이 된다면 구현하는 방법 공유 부탁드립니다. 

원하는 기능은 (...) 버튼을 눌러 새창이 나오고 원하는 내용을 입력 또는 선택하면 

그 내용이 버튼이 있는 셀의 text로 들어가게 되는 기능입니다.

감사합니다.

  • 페이스북으로 공유
  • 트위터로  공유
  • 링크 복사
  • 카카오톡으로 보내기

댓글목록

GCK써니님의 댓글

GCK써니 작성일

ReAzN 님, 안녕하세요.
그레이프시티입니다.

문의하신 내용에 대하여 현재 확인 중에 있습니다.
관련 사항이 업데이트 되는 대로 안내 드릴 수 있도록 하겠습니다.

감사합니다.
그레이프시티 드림

2 답변

WinForms윈폼 Re: 하나의 셀안에 버튼과 텍스트 표시 문의

추천1 이 글을 추천하셨습니다 비추천0

페이지 정보

작성자 GCK써니 작성일 2023-05-23 09:10 댓글 1건

본문

첨부파일

ReAzN 님, 안녕하세요.

그레이프시티입니다.


아쉽게도 말씀하신 "한 셀 안에 텍스트와 버튼을 함께 표시하는 기능"은 Spread에 내장된 기능이 아니라고 합니다. 다만 아래 코드와 같이 셀 타입을 커스터마이징 하여 말씀하신 시나리오와 유사하게 구현해보실 수 있습니다. 샘플 코드를 개발 시 참고해주시기 바랍니다.


TestActiveSheet.Cells["A10"].Value = "Test";
fpSpread1.ActiveSheet.Cells["A10"].CellType = new CustomCellType(fpSpread1);

public class CustomCellType : GeneralCellType
{
    private FpSpread _spread;

    public CustomCellType(FpSpread spread)
    {
        _spread = spread;
    }

    private int GetButtonWidth(Graphics g, float zoomFactor)
    {
        return (int)(SystemInformation.VerticalScrollBarWidth * zoomFactor * 96 / g.DpiX);
    }

    public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
    {
        int buttonWidth = GetButtonWidth(g, zoomFactor);
        g.FillRectangle(Brushes.LightGray, r.Right - buttonWidth, r.Y, buttonWidth, r.Height);

        //Change paint logic for other appearance
        Rectangle buttonRect = new Rectangle(r.Right - buttonWidth, r.Y, buttonWidth, r.Height);
        var element = VisualStyleElement.Button.PushButton.Default;
        if (VisualStyleRenderer.IsElementDefined(element))
        {
            VisualStyleRenderer renderer = new VisualStyleRenderer(element);
            Rectangle clipBounds = Rectangle.Round(g.ClipBounds);
            renderer.DrawBackground(g, buttonRect, clipBounds);
        }
        else
        {
            ControlPaint.DrawButton(g, buttonRect, ButtonState.Normal);
        }

        r.Width -= buttonWidth;
        base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);
    }

    public override object IsReservedLocation(Graphics g, int x, int y, Rectangle rc, FarPoint.Win.Spread.Appearance appearance, object value, float zoomFactor)
    {
        if (rc.Contains(x, y) && x >= rc.Right - GetButtonWidth(g, zoomFactor))
        {
            return this;
        }

        return base.IsReservedLocation(g, x, y, rc, appearance, value, zoomFactor);
    }

    public override void StartEditing(EventArgs e, bool selectAll, bool autoClipboard)
    {
        if (e is MouseEventArgs mouseEvent && mouseEvent.Clicks == 1)
        {
            var result = MessageBox.Show("Click OK to set \"Test\" to cell.", "", MessageBoxButtons.OKCancel);
            if (result == DialogResult.OK)
            {
                _spread.CancelCellEditing();
                _spread.ActiveSheet.ActiveCell.Value = "Test";
            }
            return;
        }

        base.StartEditing(e, selectAll, autoClipboard);
    }
}

감사합니다.
그레이프시티 드림

댓글목록

ReAzN님의 댓글

ReAzN 작성일

안녕하세요! 답변확인이 늦었습니다. 우선 적어주신 대안은 잘보았습니다. 저희가 C#이 아니라 VB로 개발중이어서 혹시 VB로 코드를 받아볼수 있을까요?

WinForms윈폼 Re: 하나의 셀안에 버튼과 텍스트 표시 문의

추천1 이 글을 추천하셨습니다 비추천0 채택채택

페이지 정보

작성자 GCK써니 작성일 2023-06-15 15:53 댓글 0건

본문

ReAzN 님, 안녕하세요.

그레이프시티입니다.


아래 샘플 코드를 개발 시 참고 부탁드리며, 해당 코드는 참고용 샘플이기 때문에 필요에 따라 수정하여 사용해주시기 바랍니다.

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        FpSpread1.ActiveSheet.Columns(0).CellType = New CustomCellType(FpSpread1)
    End Sub

    Public Class CustomCellType
        Inherits FarPoint.Win.Spread.CellType.GeneralCellType

        Private _spread As FarPoint.Win.Spread.FpSpread

        Public Sub New(ByVal spread As FarPoint.Win.Spread.FpSpread)
            _spread = spread
        End Sub

        Private Function GetButtonWidth(ByVal g As Graphics, ByVal zoomFactor As Single) As Integer
            Return CInt((SystemInformation.VerticalScrollBarWidth * zoomFactor * 96 / g.DpiX))
        End Function

        Public Overrides Sub PaintCell(ByVal g As Graphics, ByVal r As Rectangle, ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal value As Object, ByVal isSelected As Boolean, ByVal isLocked As Boolean, ByVal zoomFactor As Single)
            Dim buttonWidth As Integer = GetButtonWidth(g, zoomFactor)
            g.FillRectangle(Brushes.LightGray, r.Right - buttonWidth, r.Y, buttonWidth, r.Height)
            Dim buttonRect As Rectangle = New Rectangle(r.Right - buttonWidth, r.Y, buttonWidth, r.Height)
            Dim element = System.Windows.Forms.VisualStyles.VisualStyleElement.Button.PushButton.[Default]

            If System.Windows.Forms.VisualStyles.VisualStyleRenderer.IsElementDefined(element) Then
                Dim renderer As System.Windows.Forms.VisualStyles.VisualStyleRenderer = New System.Windows.Forms.VisualStyles.VisualStyleRenderer(element)
                Dim clipBounds As Rectangle = Rectangle.Round(g.ClipBounds)
                renderer.DrawBackground(g, buttonRect, clipBounds)
            Else
                ControlPaint.DrawButton(g, buttonRect, ButtonState.Normal)
            End If

            r.Width -= buttonWidth
            MyBase.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor)
        End Sub

        Public Overrides Function IsReservedLocation(ByVal g As Graphics, ByVal x As Integer, ByVal y As Integer, ByVal rc As Rectangle, ByVal appearance As FarPoint.Win.Spread.Appearance, ByVal value As Object, ByVal zoomFactor As Single) As Object
            If rc.Contains(x, y) AndAlso x >= rc.Right - GetButtonWidth(g, zoomFactor) Then
                Return Me
            End If

            Return MyBase.IsReservedLocation(g, x, y, rc, appearance, value, zoomFactor)
        End Function

        Public Overrides Sub StartEditing(ByVal e As EventArgs, ByVal selectAll As Boolean, ByVal autoClipboard As Boolean)
            Dim mouseEvent As MouseEventArgs = e

            If TypeOf e Is MouseEventArgs And CType(e, MouseEventArgs).Clicks = 1 Then
                Dim result = MessageBox.Show("Click OK to set ""Test"" to cell.", "", MessageBoxButtons.OKCancel)

                If result = DialogResult.OK Then
                    _spread.CancelCellEditing()
                    _spread.ActiveSheet.ActiveCell.Value = "Test"
                End If

                Return
            End If

            MyBase.StartEditing(e, selectAll, autoClipboard)
        End Sub

    End Class

End Class


감사합니다. 

그레이프시티 드림

댓글목록

등록된 댓글이 없습니다.

메시어스 홈페이지를 통해 제품에 대해서 더 자세히 알아 보세요!
홈페이지 바로가기
메시어스 홈페이지를 통해 제품에 대해서 더 자세히 알아 보세요!
홈페이지 바로가기
이메일 : sales-kor@mescius.com | 전화 : 1670-0583 | 경기도 과천시 과천대로 7길 33, 디테크타워 B동 1107호 메시어스(주) 대표자 : 허경명 | 사업자등록번호 : 123-84-00981 | 통신판매업신고번호 : 2013-경기안양-00331 ⓒ 2024 MESCIUS inc. All rights reserved.