你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【经验分享】stm32基于TouchGFX的GUI开发(三):radioButton 控件的使用

[复制链接]
STMCU小助手 发布时间:2022-3-9 11:17
一、创建控件
; f1 b) K" Y' I- m8 b- G' ]1、创建4个radioButton,和两个text Area控件。5 p; n' G  |5 |4 Y1 }

  d7 N. O* S# W9 u( A% t 8V7QD}5(L43LKK~0R_IS{]V.png
% d$ x, a$ k% A/ X9 K/ m
* Q) E* N$ o9 l+ m# n
  1. radioButton1 Loacation: X:56 Y: 25& v" y3 P4 s- V* J) q# B
  2. radioButton2 Loacation: X:56 Y: 78
    4 X6 G4 i+ Q* E6 y8 v" d) Z
  3. radioButton3 Loacation: X:56 Y: 129
    & b( ?( C. R7 g& g2 B
  4. radioButton4 Loacation: X:56 Y: 179( v4 U; _. }0 w( ]5 X1 ~  l: Q5 F
  5. selectedText Loacation:    X:114 Y: 137" n0 o  L1 y: A/ H( C7 ?5 B/ Z
  6. deselectedTextLoacation: X:114 Y: 189
    0 Y6 e) N( c% c9 E
  7. 同时分别设置四个radioButton的背景图片如下所示:
    1 k: r: v/ H. [& ^
  8. radioButton可以在SELECTION栏里设置默认启动时是否选择此radioButton。
复制代码

5 c: o: q( m. r* x7 i 0XB(CDEC[(N8)PNIYBJJ8YF.png
0 _" m: r  I. f* P0 a4 ~; N1 E) @6 [
然后按照下图给Text Area添加文本资源
5 {+ k$ W/ i, r, H3 Q8 L3 u' @+ O  [( [  N) D& j
{)~02V@S3PRKN{H`KSN{L`6.png 6 c% R- s, R8 j- \

. i, }% P% k8 @; A$ I  d' F+ W7 A二、实现交互
! d( V, g9 D8 E9 r8 i一共添加8个InterAction,每个radioButton添加一个selected和deselected的InterAction。
4 g; K% h5 W% b. K. I# X0 _$ p( y4 ]0 w( `6 U5 a4 Q. O8 ~) X8 G
EV`P4A}DTZNEY`QA5T60[E0.png
$ \+ m# d. u0 X" S8 Y/ S DWRJN@ZU(LBEH)`W2SMN`HN.png
# o6 d! K' u' z! \7 q7 A+ \
1 f3 H* Y6 O0 n依次向8个interactions的code里面添加如下C++代码
  X& W* o2 Z0 s$ ?
, |4 |( H8 o1 j
  1. //radioButton1的selected时执行的C++代码0 G8 p, W5 j" O. W& L
  2. Unicode::snprintf(selectedTextBuffer, 4, "%d", 1);' r) L, e$ f2 T, E3 P
  3. selectedText.resizeToCurrentText();
    - E) N6 L4 _* r1 j3 [2 j7 O. c
  4. selectedText.invalidate();
复制代码
  1. //radioButton2的selected时执行的C++代码3 ^7 t+ u% G) i1 R# I. L
  2. Unicode::snprintf(selectedTextBuffer, 4, "%d", 2);
    5 M' V! Q( `% d& {
  3. selectedText.resizeToCurrentText();
    4 t8 S% [  k. Q5 z9 u
  4. selectedText.invalidate();
复制代码
  1. //radioButton3的selected时执行的C++代码
    5 R9 q6 n: I' f* S/ }
  2. Unicode::snprintf(selectedTextBuffer, 4, "%d", 3);( K# C6 r. R) _3 C; I
  3. selectedText.resizeToCurrentText();+ K6 A6 T) |- g- O4 R' i' I
  4. selectedText.invalidate();
复制代码
  1. //radioButton4的selected时执行的C++代码3 W! i$ N, n+ a: U( b" t4 x4 i
  2. Unicode::snprintf(selectedTextBuffer, 4, "%d", 4);* W- a' K/ R1 j- v- U
  3. selectedText.resizeToCurrentText();( t7 B$ c2 w3 v" t& O) g
  4. selectedText.invalidate();
复制代码
  1. //radioButton1的deselected时执行的C++代码! d6 H0 F6 d$ L# ~5 E( K
  2. Unicode::snprintf(deselectedTextBuffer, 4, "%d", 1);: ]0 Y- F+ b1 B; Q! J( w
  3. deselectedText.resizeToCurrentText();. D: G. A( o5 ~$ H
  4. deselectedText.invalidate();
复制代码
  1. //radioButton2的deselected时执行的C++代码
    . V# p9 K: E! x, m/ y+ `, l% W
  2. Unicode::snprintf(deselectedTextBuffer, 4, "%d", 2);0 x# l9 w& H3 A
  3. deselectedText.resizeToCurrentText();( m# E# q/ s1 ~% Z
  4. deselectedText.invalidate();
复制代码
  1. //radioButton3的deselected时执行的C++代码
    ' f) w$ U8 m8 O, v+ b. y' M
  2. Unicode::snprintf(deselectedTextBuffer, 4, "%d", 3);! Y# ?' k7 u; L& d# g$ T
  3. deselectedText.resizeToCurrentText();. Z- o6 H9 ~, r. i1 F- `
  4. deselectedText.invalidate();
复制代码
  1. //radioButton4的deselected时执行的C++代码  z- [* w* `# ^1 W
  2. Unicode::snprintf(deselectedTextBuffer, 4, "%d", 4);
    ) v) X* w$ j( a7 J/ c
  3. deselectedText.resizeToCurrentText();
    1 Z. N8 O3 c3 o, {
  4. deselectedText.invalidate();
复制代码

# ~8 s, N$ E2 E7 K  \, y. T+ d; V8 [Runsimulation即可看到最终演示结果和我们预期相同。
# _0 |( k4 f1 S" ?, C( w! D3 b0 k2 L) ^3 E; }' U2 x

* R# `  o3 P  @6 N
9 E9 J0 r/ S8 |6 G6 V
2 L+ r+ S8 V3 A4 t) C
赞 收藏 评论0 发布时间:2022-3-9 11:17

举报

0个回答

所属标签

相似技术帖

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
人形机器人运动控制、感知与智能配电
半导体创新技术与应用方向
EE架构与软件定义汽车
12V/48V 汽车智能配电(SPD)
区域控制单元(ZCU)与分区架构
关注我们
st-img 微信公众号
st-img 手机版