4. As shown in Figure 1, in rectangle $A B C D$, $A B=2, B C=$ $\sqrt{3}, E$ and $F$ are the midpoints of $A B$ and $C D$ respectively. Line segments $D E$, $B F$, and $E F$ intersect diagonal $A C$ at points $M$, $N$, and $P$ respectively. The number of right triangles formed by the line segments in Figure 1 is ( ).
(A) 8
(B) 12
(C) 16
(D) 20
4.B.

Let the notation $[A]$ represent the number of right-angled triangles with $A$ as the right-angle vertex, then $[A]=2$,
Similarly, $[B]=1,[C]=2,[D]=1,[E]=3$,
$$
[F]=3,[M]=[N]=[P]=0 \text {. }
$$

Therefore, the number of right-angled triangles is
$$
2+1+2+1+3+3=12 \text {. }
$$