From 01c807c4431bb3eed545fa690863612f5fedbdfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=A0=EA=B7=9C?= Date: Sun, 30 May 2021 19:51:54 +0900 Subject: [PATCH 1/2] Finish compact chat --- Client/Forms/ControlChat.Designer.cs | 2 +- Client/Forms/ControlChat.cs | 134 ++++++++++----------------- 2 files changed, 51 insertions(+), 85 deletions(-) diff --git a/Client/Forms/ControlChat.Designer.cs b/Client/Forms/ControlChat.Designer.cs index b6231d9..8e4b351 100644 --- a/Client/Forms/ControlChat.Designer.cs +++ b/Client/Forms/ControlChat.Designer.cs @@ -63,7 +63,7 @@ private void InitializeComponent() // // lblTime // - this.lblTime.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.lblTime.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.lblTime.AutoSize = true; this.lblTime.BackColor = System.Drawing.Color.Transparent; this.lblTime.FontSize = MetroFramework.MetroLabelSize.Small; diff --git a/Client/Forms/ControlChat.cs b/Client/Forms/ControlChat.cs index 5898302..5d35508 100644 --- a/Client/Forms/ControlChat.cs +++ b/Client/Forms/ControlChat.cs @@ -30,11 +30,11 @@ public ControlChat(Chat chat, bool continuous) // 이전 채팅에 연속적일 경우 요소 제거 - PictureBox pic = null; + Control dataControl = null; // 데이터 표시 if (chat.type == ChatType.Image) { - pic = new PictureBox(); + PictureBox pic = new PictureBox(); // 이미지 pic.Image = chat.image; @@ -59,16 +59,17 @@ public ControlChat(Chat chat, bool continuous) Height = pic.Height + verticalSpace; // 시간 라벨 위치 - lblTime.Location = new Point(Math.Max( - pic.Location.X, pic.Location.X + pic.Width - lblTime.Width), - lblTime.Location.Y); + lblTime.Left = Math.Max(pic.Location.X, pic.Location.X + pic.Width - lblTime.Width); // 컨트롤 추가 및 제거 Controls.Remove(lblText); Controls.Add(pic); + dataControl = pic; } else { + dataControl = lblText; + // 텍스트부터 컨트롤에 넣기 lblText.Text = chat.text; @@ -85,95 +86,60 @@ public ControlChat(Chat chat, bool continuous) sizef = g.MeasureString(lblText.Text, Font); lblText.Width = (int)sizef.Width + 3; - lblTime.Location = new Point(Math.Max( - lblText.Location.X, lblText.Location.X + lblText.Width - lblTime.Width), - lblTime.Location.Y); + lblTime.Left = Math.Max(lblText.Location.X, lblText.Location.X + lblText.Width - lblTime.Width); } } - // 내가 보낸 것일 경우 - if (chat.empId == Program.employee.id) + if (continuous) { - // 전체 높이에 대한 Offset 다시 지정 - int needSubstractheight = lblName.Height + lblName.Margin.Bottom; - verticalSpace -= needSubstractheight; - - // 데이터 위치 - if (chat.type == ChatType.Image) - { - // 우측 정렬 후 lblName 높이만큼 위로 올리기 - pic.Location = new Point(Width - Padding.Right - pic.Width, pic.Location.Y - needSubstractheight); - pic.Anchor = AnchorStyles.Top | AnchorStyles.Right; - - // 전체 높이 지정 - Height = pic.Height + verticalSpace; - } - else - { - // 우측 정렬 후 lblName 높이만큼 위로 올리기 - lblText.Location = new Point(Width - Padding.Right - lblText.Width, lblText.Location.Y - needSubstractheight); - lblText.Anchor = AnchorStyles.Top | AnchorStyles.Right; - lblText.BackColor = Color.LemonChiffon; - - // 전체 높이 지정 - Height = lblText.Height + verticalSpace; - } - - // 시계 위치 - lblTime.TextAlign = ContentAlignment.TopLeft; - lblTime.Anchor = AnchorStyles.Top | AnchorStyles.Right; - lblTime.Location = new Point(Math.Min( - chat.type == ChatType.Image ? pic.Location.X : lblText.Location.X, - Width - Padding.Right - lblTime.Width), - lblTime.Location.Y); + dataControl.Top = 4; + Height = dataControl.Top + dataControl.Height + lblTime.Height; // 불필요 컨트롤 지우기 Controls.Remove(picProfile); Controls.Remove(lblName); } - else - { - // 다른 사람이 보낸 것이 연속적일 경우 - if (continuous) - { - // 전체 높이에 대한 Offset 다시 지정 - int needSubstractheight = lblName.Height + lblName.Margin.Bottom; - verticalSpace -= needSubstractheight; - - // 데이터 위치 - if (chat.type == ChatType.Image) - { - // 우측 정렬 후 lblName 높이만큼 위로 올리기 - pic.Location = new Point(pic.Location.X, pic.Location.Y - needSubstractheight); - - // 전체 높이 지정 - Height = pic.Height + verticalSpace; - } - else - { - // 우측 정렬 후 lblName 높이만큼 위로 올리기 - lblText.Location = new Point(lblText.Location.X, lblText.Location.Y - needSubstractheight); - - // 전체 높이 지정 - Height = lblText.Height + verticalSpace; - } - - - - // 불필요 컨트롤 지우기 - Controls.Remove(picProfile); - Controls.Remove(lblName); - } - } - // 연속될 경우 패딩 제거 - if (continuous) - { - int needSubstractHeight = Padding.Top - 4; - - Height -= needSubstractHeight; - Padding = new Padding(Padding.Left, 4, Padding.Right, Padding.Bottom); - } + // 내가 보낸 것일 경우 + //if (chat.empId == Program.employee.id) + //{ + // // 전체 높이에 대한 Offset 다시 지정 + // int needSubstractheight = lblName.Height + lblName.Margin.Bottom; + // verticalSpace -= needSubstractheight; + + // // 데이터 위치 + // if (chat.type == ChatType.Image) + // { + // // 우측 정렬 후 lblName 높이만큼 위로 올리기 + // pic.Location = new Point(Width - Padding.Right - pic.Width, pic.Location.Y - needSubstractheight); + // pic.Anchor = AnchorStyles.Top | AnchorStyles.Right; + + // // 전체 높이 지정 + // Height = pic.Height + verticalSpace; + // } + // else + // { + // // 우측 정렬 후 lblName 높이만큼 위로 올리기 + // lblText.Location = new Point(Width - Padding.Right - lblText.Width, lblText.Location.Y - needSubstractheight); + // lblText.Anchor = AnchorStyles.Top | AnchorStyles.Right; + // lblText.BackColor = Color.LemonChiffon; + + // // 전체 높이 지정 + // Height = lblText.Height + verticalSpace; + // } + + // // 시계 위치 + // lblTime.TextAlign = ContentAlignment.TopLeft; + // lblTime.Anchor = AnchorStyles.Top | AnchorStyles.Right; + // lblTime.Location = new Point(Math.Min( + // chat.type == ChatType.Image ? pic.Location.X : lblText.Location.X, + // Width - Padding.Right - lblTime.Width), + // lblTime.Location.Y); + + // // 불필요 컨트롤 지우기 + // Controls.Remove(picProfile); + // Controls.Remove(lblName); + //} BackColor = Color.FromArgb(new Random(DateTime.Now.Millisecond).Next()); } From 02ba9b26493d4d1ff8a541855a14a04460d7623f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=A0=EA=B7=9C?= Date: Sun, 30 May 2021 20:06:21 +0900 Subject: [PATCH 2/2] Finish of room like kakaotalk --- Client/Forms/ControlChat.Designer.cs | 6 +-- Client/Forms/ControlChat.cs | 59 +++++++--------------------- 2 files changed, 18 insertions(+), 47 deletions(-) diff --git a/Client/Forms/ControlChat.Designer.cs b/Client/Forms/ControlChat.Designer.cs index 8e4b351..08d8287 100644 --- a/Client/Forms/ControlChat.Designer.cs +++ b/Client/Forms/ControlChat.Designer.cs @@ -38,7 +38,7 @@ private void InitializeComponent() // // lblText // - this.lblText.BackColor = System.Drawing.SystemColors.Control; + this.lblText.BackColor = System.Drawing.Color.White; this.lblText.FontSize = MetroFramework.MetroLabelSize.Small; this.lblText.Location = new System.Drawing.Point(48, 35); this.lblText.Margin = new System.Windows.Forms.Padding(0); @@ -46,6 +46,7 @@ private void InitializeComponent() this.lblText.Size = new System.Drawing.Size(274, 50); this.lblText.TabIndex = 0; this.lblText.Text = "This returns"; + this.lblText.UseCustomBackColor = true; this.lblText.WrapToLine = true; // // lblName @@ -63,7 +64,7 @@ private void InitializeComponent() // // lblTime // - this.lblTime.Anchor = System.Windows.Forms.AnchorStyles.Bottom; + this.lblTime.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.lblTime.AutoSize = true; this.lblTime.BackColor = System.Drawing.Color.Transparent; this.lblTime.FontSize = MetroFramework.MetroLabelSize.Small; @@ -74,7 +75,6 @@ private void InitializeComponent() this.lblTime.Size = new System.Drawing.Size(59, 15); this.lblTime.TabIndex = 20; this.lblTime.Text = "오전 12:38"; - this.lblTime.TextAlign = System.Drawing.ContentAlignment.TopRight; this.lblTime.UseCustomBackColor = true; this.lblTime.UseCustomForeColor = true; // diff --git a/Client/Forms/ControlChat.cs b/Client/Forms/ControlChat.cs index 5d35508..99ebfbb 100644 --- a/Client/Forms/ControlChat.cs +++ b/Client/Forms/ControlChat.cs @@ -68,8 +68,6 @@ public ControlChat(Chat chat, bool continuous) } else { - dataControl = lblText; - // 텍스트부터 컨트롤에 넣기 lblText.Text = chat.text; @@ -88,9 +86,12 @@ public ControlChat(Chat chat, bool continuous) lblTime.Left = Math.Max(lblText.Location.X, lblText.Location.X + lblText.Width - lblTime.Width); } + dataControl = lblText; } - if (continuous) + // 연속적일 경우 프로필, 이름을 제거 + // 시계는 다음 채팅이 들어왔을 때 SetContinuous() 호출 되서 제거 됨 + if (continuous || chat.empId == Program.employee.id) { dataControl.Top = 4; Height = dataControl.Top + dataControl.Height + lblTime.Height; @@ -101,47 +102,17 @@ public ControlChat(Chat chat, bool continuous) } // 내가 보낸 것일 경우 - //if (chat.empId == Program.employee.id) - //{ - // // 전체 높이에 대한 Offset 다시 지정 - // int needSubstractheight = lblName.Height + lblName.Margin.Bottom; - // verticalSpace -= needSubstractheight; - - // // 데이터 위치 - // if (chat.type == ChatType.Image) - // { - // // 우측 정렬 후 lblName 높이만큼 위로 올리기 - // pic.Location = new Point(Width - Padding.Right - pic.Width, pic.Location.Y - needSubstractheight); - // pic.Anchor = AnchorStyles.Top | AnchorStyles.Right; - - // // 전체 높이 지정 - // Height = pic.Height + verticalSpace; - // } - // else - // { - // // 우측 정렬 후 lblName 높이만큼 위로 올리기 - // lblText.Location = new Point(Width - Padding.Right - lblText.Width, lblText.Location.Y - needSubstractheight); - // lblText.Anchor = AnchorStyles.Top | AnchorStyles.Right; - // lblText.BackColor = Color.LemonChiffon; - - // // 전체 높이 지정 - // Height = lblText.Height + verticalSpace; - // } - - // // 시계 위치 - // lblTime.TextAlign = ContentAlignment.TopLeft; - // lblTime.Anchor = AnchorStyles.Top | AnchorStyles.Right; - // lblTime.Location = new Point(Math.Min( - // chat.type == ChatType.Image ? pic.Location.X : lblText.Location.X, - // Width - Padding.Right - lblTime.Width), - // lblTime.Location.Y); - - // // 불필요 컨트롤 지우기 - // Controls.Remove(picProfile); - // Controls.Remove(lblName); - //} - - BackColor = Color.FromArgb(new Random(DateTime.Now.Millisecond).Next()); + if (chat.empId == Program.employee.id) + { + // 데이터 위치 + dataControl.Left = Width - dataControl.Width - Padding.Right; + dataControl.Anchor = AnchorStyles.Top | AnchorStyles.Right; + dataControl.BackColor = Color.LemonChiffon; + + // 시계 위치 + lblTime.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + lblTime.Left = Math.Min(dataControl.Left, Width - Padding.Right - lblTime.Width); + } } public void SetContinuous()